我有一个表格,用户可以在其中选择可用的技能:
<form name="myForm" action="jssearch.php" method="post">
<input type="checkbox" name="chk1[]" value="1">Helpdesk Support
<input type="checkbox" name="chk1[]" value="2">DB Admin<br>
<input type="checkbox" name="chk1[]" value="3">C++ Programming
<input type="checkbox" name="chk1[]" value="5">HTML<br>
<input type="checkbox" name="chk1[]" value="6">PHP<br>
<input type="checkbox" name="chk1[]" value="7">Memory Dump Analysis<br>
<input type="checkbox" name="chk1[]" value="8">SQL<br><br>
<input type="submit" name="Update" value="Search">
</form>
基于这些选择,我想针对多对多表运行查询并显示包含所选技能的可用工作。
到目前为止,这是我的查询:
<?php
session_start();
mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("jobsearch") or die(mysql_error());
$variable=$_POST['chk1'];
foreach ($variable as $variablename)
{
$query = mysql_query(
"SELECT jobs.jobid AS job_id, jobs.jobtitle AS
job_title,jobs.salary AS salary_desc, GROUP_CONCAT(skills.Desc) AS skills_desc
FROM jobskillsjoin
INNER JOIN jobs ON jobs.jobid = jobskillsjoin.JobID
INNER JOIN skills ON skills.skill_id = jobskillsjoin.SkillID
WHERE skills.skill_id = '".$variablename."'
GROUP BY jobs.jobid
")
or die(mysql_error());
}
echo "<table border='1'>
<tr>
<th>Job ID</th>
<th>Job Title</th>
<th>Skills required</th>
<th>Salary Offered</th>
</tr>";
while($row = mysql_fetch_array($query))
{
echo "<tr>";
echo "<td>" . $row['job_id'] . "</td>";
echo "<td>" . $row['job_title'] . "</td>";
echo "<td>" . $row['skills_desc'] . "</td>";
echo "<td>" . $row['salary_desc'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
但是发生的情况是,只有最后选择的技能会通过查询运行。不过,我想显示所有“点击”。
我想我需要一个循环和一个数组,但我不知道该怎么做。