Page 1 of 1

search a mysql database using checkboxes

Posted: Wed Sep 28, 2005 6:26 am
by leewad
Hi

I`m wanting to have a refined search where you can have different checkboxes on a form for fields to search from i e

search for a car less than £500, aircon, leather, CD using checkboxes could anyone help me with this? I have the checkboxes in an array but not sure how to pull the info from the database.

Thanks

Posted: Wed Sep 28, 2005 6:32 am
by Jenk
What you are aiming to achieve is to build a (SQL) Statement to pass to the Database.

Essentially a string.

So you would have sub-strings stored which you would include if the relevant checkbox is checked.

A very brief example, for the receiving page:

Code: Select all

<?php

$sql = "SELECT * FROM cars"

if (isset($_POST['chkbox1']) {

$sql .= " WHERE airCon = 1";

}

mysql_query($sql);

?>