Billybong007
IS-IT--Management
I'm trying to perform a search on an SQL table using the code below - but it fails to work.
I have a form when a user can search/filter using multiple variables i.e. locations, industry, job type.
If i do a simple select statement using a WHERE with only one variable it works fine and if i set and WHERE and AND statement then it will find everything match both - the problem is that it won't find anything if only 1 option is searched when i Use the WHERE and AND statement together.
To over come this I tried making an isset statement that if the variable is set then search for it, else ignore it ... but it doesn't work
Can anyone tell me how i can search for multiple variables, but still allowing a SEARCH ALL function
Many thank,
Billybong
I have a form when a user can search/filter using multiple variables i.e. locations, industry, job type.
If i do a simple select statement using a WHERE with only one variable it works fine and if i set and WHERE and AND statement then it will find everything match both - the problem is that it won't find anything if only 1 option is searched when i Use the WHERE and AND statement together.
To over come this I tried making an isset statement that if the variable is set then search for it, else ignore it ... but it doesn't work
Code:
$locations = $_POST['locations'];
$industry = $_POST['industry'];
$job_type = $_POST['job_type'];
$query = "SELECT *"
. "\n FROM #__jobposts"
. "\n WHERE type = '". $job_type."'"
if(isset($locations)){
$query.="\n AND location = '".$locations."'";
}
. "\n ORDER by date desc"
;
Can anyone tell me how i can search for multiple variables, but still allowing a SEARCH ALL function
Many thank,
Billybong