Hi all. I've a problem with a SELECT statement I could use some help with.
To explain the problem first, I've 6 drop downs set up, By default, all six are set to "All", and the user can change as many as the like (including none of them) to filter a table of date shown below them (the data comes from a recordset). That recordset is then defined by an SQL query, where each WHERE is added if the option selected was not "All". So here's the code I'm using to create the SQL query:
$catagory = 'All';
if (isset($_GET['eventCatagory'])) {
$catagory = $_GET['eventCatagory'];
}
$county = 'All';
if (isset($_GET['eventCounty'])) {
$county = $_GET['eventCounty'];
}
$town = 'All';
if (isset($_GET['eventTown'])) {
$town = $_GET['eventTown'];
}
$day = 'All';
if (isset($_GET['eventDate_Day'])) {
$day = $_GET['eventDate_Day'];
}
$month = 'All';
if (isset($_GET['eventDate_Month'])) {
$month = $_GET['eventDate_Month'];
}
$year = 'All';
if (isset($_GET['eventDate_Year'])) {
$year = $_GET['eventDate_Year'];
}
mysql_select_db($database_conn, $conn);
if($catagory!='All' OR $county!='All' OR $town!='All' OR $day!='All' OR $month!='All' OR $year!='All')
{
$query_rsEvents = "`SELECT * FROM tblEvents WHERE 1 = 1";
if($catagory != 'All'){
$query_rsEvents = " AND eventCategory = '$catagory'";
}
if($county != 'All'){
$query_rsEvents = " AND eventCounty = '$county'";
}
if($town != 'All'){
$query_rsEvents = " AND eventTown = '$town'";
}
if($day != 'All'){
$query_rsEvents = " AND eventDay = '$day'";
}
if($month != 'All'){
$query_rsEvents = " AND eventMonth = '$month'";
}
if($year != 'All'){
$query_rsEvents = " AND eventYear = '$year'";
}
$query_rsEvents = " ORDER BY eventTotalDate ASC`";
}
else
{
$query_rsEvents = "SELECT * FROM tblEvents ORDER BY eventTotalDate ASC";
}
The code works fine if all are set to all, but as soon as I populate any of the drop downs and press submit, the page turns white, i.e. the contends of the first IF is breaking the code.
Any thoughts on a better way to create the query?