Hi,
I am trying to create a select statement that will extract data from a MySQL database when the user selects a number of options from 4 drop down list boxes.
Here is my code for $where1 (there are 4 in total).
switch($_POST['company_size'])
{
case 1:
$where1 = "company_size LIKE 'Small'";
break;
case 2:
$where1 = "company_size LIKE 'Medium'";
break;
case 3:
$where1 = "company_size LIKE 'Large'";
break;
default:
break;
}
This all works fine but I am not sure how to construct the where clause so that only one or up to all four options can be selected from the options.
$whereclause = $where1;
if($whereclause == "")
{
$whereclause = $where2;
}
else
{
if($whereclause2 == "")
{
$whereclause = $where3;
}
else
{
if($whereclause3 == "")
{
$whereclause = $where4;
}
else
{
if($where4 != "")
{
$whereclause .= " AND " . $where2 .= " AND " . $where3 .= " AND " . $where4;
}
}
if($whereclause != "")
{
$whereclause = " WHERE " . $whereclause;
}
$sql = "SELECT name, County, sector, company_size
FROM beacon
$whereclause";
Anybody able to help?!