I am currently trying to search a job table.
On the search page I have title, industry and location search fields. However at the moment I can only get results returned if I specify the location.
If I search for the specific job title, or industry or both I cannot get any results returned. I guess this is a problem with my SQL statement - but I cannot see anything wrong with it.
Any ideas? Here is the code:
<?php
//Get variables from search.php
$title = $HTTP_POST_VARS['title'];
$industry = $HTTP_POST_VARS['sector'];
$location = $HTTP_POST_VARS['location'];
//Load Database Connection & DB details
include("config.php");
//SQL query
$sql = "SELECT jobid, date, title, description, location, industry, salary FROM job WHERE title LIKE '%$title%' ";
if($industry!= "")
$sql_where = " AND industry = '$industry'";
if($location!= "")
$sql_where = " AND location = '$location'";
$sql = $sql.$sql_where;
//Execute SQL and exit if failure
$sql_result = mysql_query($sql) or die('SQL Error');
$num_rows = mysql_num_rows($sql_result);
if ($num_rows == 0)
{
echo 'Sorry your search did not return any results. Please return to the search page <a href=search.php>here</a>';
}
while ($row = mysql_fetch_array($sql_result)){
$jobid = $row["jobid"];
$date= $row["date"];
$title = $row["title"];
$desc = $row["description"];
$location = $row["location"];
$skills = $row["skills"];
$salary = $row["salary"];
$industry = $row["industry"];
$contact = $row["contactid"];
print "<table><tr><td>Job ID: $jobid</td></tr>";
print "<tr><td>Date: $date</td></tr>";
print "<tr><td>Description: $desc</td></tr>";
print "<tr><td>Location: $location</td></tr>";
print "<tr><td>Salary: $salary</td></tr></table>";
print "For more information, please click <a href=result_details.php?jobid=$jobid>here</a>";
}
?>