PDA

View Full Version : MySQL Inventory Search Engine Help



bernk
July 15th, 2008, 04:59 PM
I'm working on a car dealership site and have to setup an inventory database which can be searched with the common criteria found on these kids of sites:

make, model, year range, price range, milage, etc.

My question is this...if the user only selects a make and a price range, then the other fields will be "". So my select statment would look something like this:

SELECT * FROM inventory WHERE make="Audi" && model="" && milage="" && price BETWEEN low_price AND high_price; ...you get the idea?

How can I get around this, I'm a noob when it comes to database stuff...

jwilliam
July 16th, 2008, 10:46 PM
Use 'if' statements to leave out fields that are blank from the query.




$sql = "Whatever...";
$model = mysql_real_escape_string($_POST['model']);
$sql .= strlen(trim($model)) ? " AND model='$model'" : '';



Hope that helps...