$uid);
/* execute the query */
mysql_query($query);
}
/* helper function for insert_skills().
removes all rows in $table with $uid */
function purge_lookup($table, $uid) {
$q = "DELETE FROM $table, WHERE uid = '$uid'";
mysql_query($q);
}
/* helper function for insert_skills().
generates the sctual SQL query */
function create_checkbox_query($arr, $table, $uid) {
$q = "INSERT INTO $table (uid, skill_id) VALUES";
foreach ($arr as $check) {
$q .= " ( $uid , $check )" . ",";
}
/* remove the last comma and return */
return substr($q, 0, -1);
}
?>
很简单吧。现在你知道如何从表const_skill读记录来动态创建一个表单,也知道如何保存用户选择的技能到表lookup_skills中。下面我们要做什么?让我们看一下搜索吧
搜索
当一个雇主来找一个网络开发人员时,他来到你的搜索页面,你可以显示同样的一个表单并且允许他选择他想要雇员拥有的技能。你取到了他选中的技能的数组,然后你可以遍历这个数组,用一个SQL语句找出拥有此技能的求职者,你可以显示这个列表或结果,并允许搜索者点一个项目显示它的详细信息。下面的这个函数描述了如何创建这个查询语句:
/* builds a query to search for the skills
checked off in the $skills array */
function skill_search($skills) {
if (!empty($skills)) {
$query = "SELECT DISTINCT user.username
FROM user, const_skills, lookup_skills
WHERE lookup_skills.uid = user.id
AND lookup_skills.skill_id = const_skills.id ";
$query .= " AND (";
foreach ($skills as $check) {
$query .= " const_skills.id = $check OR";
}
/* remove the final OR */
$query = substr($query, 0, -2);
$query .= ")";
$count = count($skills);
$query .= " GROUP BY user.username HAVING count(user.username) >= $count";
$query .= ";";
return $query;
}
}
?
/* execute the query */
mysql_query($query);
}
/* helper function for insert_skills().
removes all rows in $table with $uid */
function purge_lookup($table, $uid) {
$q = "DELETE FROM $table, WHERE uid = '$uid'";
mysql_query($q);
}
/* helper function for insert_skills().
generates the sctual SQL query */
function create_checkbox_query($arr, $table, $uid) {
$q = "INSERT INTO $table (uid, skill_id) VALUES";
foreach ($arr as $check) {
$q .= " ( $uid , $check )" . ",";
}
/* remove the last comma and return */
return substr($q, 0, -1);
}
?>
很简单吧。现在你知道如何从表const_skill读记录来动态创建一个表单,也知道如何保存用户选择的技能到表lookup_skills中。下面我们要做什么?让我们看一下搜索吧
搜索
当一个雇主来找一个网络开发人员时,他来到你的搜索页面,你可以显示同样的一个表单并且允许他选择他想要雇员拥有的技能。你取到了他选中的技能的数组,然后你可以遍历这个数组,用一个SQL语句找出拥有此技能的求职者,你可以显示这个列表或结果,并允许搜索者点一个项目显示它的详细信息。下面的这个函数描述了如何创建这个查询语句:
/* builds a query to search for the skills
checked off in the $skills array */
function skill_search($skills) {
if (!empty($skills)) {
$query = "SELECT DISTINCT user.username
FROM user, const_skills, lookup_skills
WHERE lookup_skills.uid = user.id
AND lookup_skills.skill_id = const_skills.id ";
$query .= " AND (";
foreach ($skills as $check) {
$query .= " const_skills.id = $check OR";
}
/* remove the final OR */
$query = substr($query, 0, -2);
$query .= ")";
$count = count($skills);
$query .= " GROUP BY user.username HAVING count(user.username) >= $count";
$query .= ";";
return $query;
}
}
?
| 对此文章发表了评论 |
