这个有点类似于权限管理可以使用质数方法或者二进制方法
我说一下二进制的方法
岗位单独设置一个表
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).")";
这样的查询语句就可以获取岗位名称了. |