i’m having a little trouble with an elseif MySQL query i’m using to search my database depending on what selections are made in a form.
It’s not returning an error, but its not returning the results it should, so i’m assuming the second elseif query isn’t running at all. The first one works (when the right selections are made of course).
Can anyone point out what i’m doing wrong?
<?php
$jobtype = $_POST['jobtype'];
$country = $_POST['countries'];
$city = $_POST['cities'];
if ($jobtype=="All Jobs" && (isset($_POST['countries'])) && $city !="Whole Region")
{
$result = mysql_query(
"SELECT *
FROM jobinformation
WHERE country = '$country' AND county = '$city'
ORDER BY job_id DESC");
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
$rows=mysql_num_rows($result);
for ($j = 0; $j < $rows ; ++$j)
{
$row = mysql_fetch_row($result);
echo 'jobtitle: ' . $row[3] .'<br />';
echo 'Company: ' . $row[2] .'<br />';
}
}
elseif ($jobtype=="All Jobs" && (isset($_POST['countries'])) && $jobtype=="Whole Region")
{
$result = mysql_query(
"SELECT *
FROM jobinformation
WHERE country = '$country'
ORDER BY job_id DESC");
etc etc (same as above)
}
looks like this:
Should be this:
You’re check against
$jobtypein the else if when you check it against$cityin the ifAlso if the first 2 parts of the if statement are the same you don’t need an
elseifhere you can just use an else