PHP/Mysql select case search form help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bikeman
Forum Newbie
Posts: 1
Joined: Thu Apr 30, 2009 10:56 am

PHP/Mysql select case search form help

Post by bikeman »

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

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;
}
 
 
Last edited by Benjamin on Thu Apr 30, 2009 12:20 pm, edited 1 time in total.
Reason: Added code tags.
Post Reply