关于一个mysql 设计的问题[转]
关于一个mysql 设计的问题本文转载自喜悦村 http://www.phpx.com/happy/thread-136209-1-1.html 原作者:蟋蟀 是这样的,我有一个简历表 比如有字段 姓名 性别 年龄 求职岗位类别 工作地点 问题就出在岗位类别,因为一个人可能有很多个岗位类别 我现在将每个岗位类别用分号分开,如 ;1701;1171;1891;1999;1961; 每组数字多是一个分类 ,如1701是计算机it软件类 那么查询的时候, like "';%1701%;" 这样的话索引就不起作用,问有没有好的办法! 这个有点类似于权限管理可以使用质数方法或者二进制方法 我说一下二进制的方法 岗位单独设置一个表 create table station( post_id int(11) not null default 0, post_name varchar(32) not null default ''); 对于resume 姓名 性别 年龄 求职岗位类别 工作地点 create table resume( resume_id int(11) not null primary key auto_increment, name varchar(32) not null, sex enum("Y","n"), age tinyint(2) not null, post_id int(11) not null, address text); 这样建立简历表 处理的时候对于不同的岗位 假设岗位表中 1(pow(2,0)) 程序员 2(pow(2,1)) 分析员 4(pow(2,2)) 架构师 注意post_id必须为pow(2,n)数 当一个人记录即是程序员又是分析员的时候 简历表中的记录为 xs y 20 3 beijing的时候 由于post_id为程序员和设计员和,所以可以用函数解析 function parse_station($type) { $station_list = array(从station表中取出所有的岗位列表数组) $arr = array_keys($station_list); //如 array(1,2,4,8)这样的数组 array_pop($arr); $total = array_sum($arr); arsort($arr); //不是数字或者大于所有权限值之和 if (!is_numeric($type) || $type > $total) { return false; } while ($type > 0) { $f_elem = array_shift($arr); $var_eval = "if ($type >= $f_elem) { $type = $type % $f_elem; $new_arr[] = $f_elem; } "; foreach ($arr as $value) { $var_eval .= " else if ($type >= $value) { $type = $type % $value; $new_arr[] = $value; }"; } eval($var_eval); } return @array_unique($new_arr); } 这样把 $arr = parse_station(3); 就是array(1,2)这样的数组 在执行 select post_name from station where post_id in (".implode(",",$arr).")"; 这样的查询语句就可以获取岗位名称了.
上一主题: php过滤多个空格为一个空格 下一主题: 向mysql中插入不重复的记录
查找相关文章:mysql 多对多
一 二 三 四 五 六 日 1
2 3
4
5
6
7
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Copyright ©2005 - 2007 老李的个人日志. All Rights Reserved
本日志程式及模版由老李(QQ:8989215)编写维护
粤ICP备06043306号