I have 5 variables which can either be true or false and I have to generate different sql SELECT statements for each different possible outcome. Right now I have a ton of if else statements but I'm wondering if theres a smarter way to do this?
so for example, i have
if (x=true AND y=false AND z=false AND a=false AND b =false) {
$sql= "SELECT...."
} else if(x=true AND y=true AND z=false AND a=false AND b=false) {
$sql= "SELECT...."
}
The first select statement is if the user entered text and didnt select anything else:
$sql="SELECT CompanyName, Keywords, Product, Industry, Link, region, hot FROM searchtest_tbl WHERE Keywords LIKE '%$formSearch%' OR CompanyName LIKE '%$formSearch%' OR Product LIKE '%$formSearch%' OR Industry LIKE '%$formSearch%' ORDER BY hot DESC, CompanyName";
this statement is if they only selected from the Industry dropdown:
$sql="SELECT CompanyName, Product, Industry, Link, hot, region FROM searchtest_tbl WHERE Industry='$formIndustry' ORDER BY hot DESC, CompanyName";
and here is one if they entered text, selected an industry, but didnt select anythign else:
$sql="SELECT CompanyName, Product, Industry, Link, hot, region FROM searchtest_tbl WHERE Industry='$formIndustry' AND (Keywords LIKE '%$formSearch%' OR CompanyName LIKE '%$formSearch%' OR Product LIKE '%$formSearch%') ORDER BY hot DESC, CompanyName";
The rest are basically like this, but if the other fields are selected it will say WHERE Product='$formProduct' AND.... etc