PHP/Mysql select case search form help
Posted: Thu Apr 30, 2009 11:12 am
Hi, got a problem with my search form (see code below). In a nutshell the search uses switch case based upon the vehicle price and then matches other variables such as fule, transmission etc.
This works fine except when an input variable is any (null) i.e. if the user selects 'ANY' for the fuel variable it must select all vehicles regardless of fuel type, likewise for manufacturer etc.
I am new to programming and guess that I need to include some if/then statements within the switch case code but am at a loss to know what to do.
Can anyone help? thanks
This works fine except when an input variable is any (null) i.e. if the user selects 'ANY' for the fuel variable it must select all vehicles regardless of fuel type, likewise for manufacturer etc.
I am new to programming and guess that I need to include some if/then statements within the switch case code but am at a loss to know what to do.
Can anyone help? thanks
Code: Select all
$colname_rs_vehicledetails = "-1";
if (isset($_GET['price'])) {
$colname_rs_vehicledetails = (get_magic_quotes_gpc()) ? $_GET['price'] : addslashes($_GET['price']);
}
mysql_select_db($database_cardealer, $cardealer);
/* select by price */
switch($colname_rs_vehicledetails)
{
case "5000";
$query_rs_vehicledetails = sprintf("SELECT * FROM vehicledata, fuel, registration, transmission
WHERE price <= 5000
AND vehicledata.fuel = ". $_GET['fuel'] ."
AND vehicledata.transmission = ". $_GET['transmission'] ."
AND vehicledata.manufacturer = ". $_GET['manufacturer'] ."
AND vehicledata.fuel = fuel.fuelID AND vehicledata.registration = registration.RegistrationID AND vehicledata.transmission = transmission.transmissionID
ORDER BY price ASC", $colname_rs_vehicledetails);
break;
case "10000";
$query_rs_vehicledetails = sprintf("SELECT * FROM vehicledata, fuel, registration, transmission WHERE price > 5000 AND price < 10000
AND vehicledata.fuel = ". $_GET['fuel'] ."
AND vehicledata.transmission = ". $_GET['transmission'] ."
AND vehicledata.manufacturer = ". $_GET['manufacturer'] ."
AND vehicledata.fuel = fuel.fuelID AND vehicledata.registration = registration.RegistrationID AND vehicledata.transmission = transmission.transmissionID
ORDER BY price ASC", $colname_rs_vehicledetails);
break;
case "10001";
$query_rs_vehicledetails = sprintf("SELECT * FROM vehicledata, fuel, registration, transmission WHERE price > 10000
AND vehicledata.fuel = ". $_GET['fuel'] ."
AND vehicledata.transmission = ". $_GET['transmission'] ."
AND vehicledata.manufacturer = ". $_GET['manufacturer'] ."
AND vehicledata.fuel = fuel.fuelID AND vehicledata.registration = registration.RegistrationID AND vehicledata.transmission = transmission.transmissionID
ORDER BY price ASC", $colname_rs_vehicledetails);
break;
default;
$query_rs_vehicledetails = sprintf("SELECT * FROM vehicledata, fuel, registration, transmission
WHERE vehicledata.fuel = ". $_GET['fuel'] ."
AND vehicledata.transmission = ". $_GET['transmission'] ."
AND vehicledata.manufacturer = ". $_GET['manufacturer'] ."
AND vehicledata.fuel = fuel.fuelID AND vehicledata.registration = registration.RegistrationID AND vehicledata.transmission = transmission.transmissionID
ORDER BY price ASC", $colname_rs_vehicledetails);
break;
}