I have a form, where users select available skills:
<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>
Based on these selections, I want to run a query against a many-to-many table and display the available jobs that contain the skills selected.
This is my query so far:
<?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>";
?>
What happens though is that only the last skill selected is run through the query. I want to display all the "hits" though.
I think I need a loop and an array but I'm not sure how to do it.