recordsets with multiple options - AND, OR If Else and the "Any" Rule
Hi,
Been trying to get this to work for days now... I have a form with drop down lists that feeds through variables to a search page... The Recordset Jobsearch2 shown below works great so long as a user chooses and option that has info in the DB.... ie all fields must be present. I cannot seem to work out how to achieve and Any rule?...
I have had 2 options suggested to me...
a) the code below...
if(isset($searchsector) && $searchsector !== "") {
$query_jobsearch2 .= ' AND Sector LIKE "%' . mysql_real_escape_string($searchsector) . '%"';
}
putting this in for each option..... but If Im told I have to add this in before the "$jobsearch2 = mysql_query" line... but when I do this the recordset disappears\is deleted...
b) Using an Array and "Implode" - this wouldbe great I'm sure if I had any clue how to do this and what it meant.
MY CURRENT CODE
<?php require_once('Connections/steelbakercouk_473245_db1.php'); ?>
<?php
$searchsector = $_POST['Sector'];
$searchlocation = $_POST['clocation'];
$searchmin = $_POST['minsalary'];
$searchmax = $_POST['maxsalary'];
$searchtype = $_POST['Type'];
?>
<?php
mysql_select_db($database_steelbakercouk_473245_db1, $steelbakercouk_473245_db1);
$query_jobsearch2 = "SELECT jobs.clocation, jobs.Ref_id, jobs.RefCode, jobs.jobtitle, jobs.blurb, jobs.Consultant, jobs.Salary, jobs.tlocation, jobs.Sector, jobs.Type FROM jobs WHERE jobs.Salary BETWEEN '$searchmin' AND '$searchmax' AND clocation = '$searchlocation' AND jobs.Sector = '$searchsector' AND jobs.Type = '$searchtype'";
$jobsearch2 = mysql_query($query_jobsearch2, $steelbakercouk_473245_db1) or die(mysql_error());
$row_jobsearch2 = mysql_fetch_assoc($jobsearch2);
$totalRows_jobsearch2 = mysql_num_rows($jobsearch2);
?>
Please help... ... pulling my hair out!
Thanks
