Forum Moderators: coopster
<form name="theForm" method="post" action="advanced_search.php">
<input type="submit" name="Submit" value="Search" />
<select name="categories" >
<option value=""> Select Categoy</option>
</select>
<select name="state" >
<option value=""> Select state</option>
</select>
<select name="city" >
<option value=""> Select city</option>
</select>
if (isset($_POST['Submit'])) {
$select = "SELECT * FROM classifieds";
$where = " WHERE ( authorized = '1')";
$where .= " AND (cat = '" . $categories . "' AND state_id = '" . $state . "' AND city_id = '" . $city . "')";
$where .= " AND (state_id = '" . $state . "' )";
$where .= " AND (city_id = '" . $city . "' )";
$q = $select . $where . ' ORDER BY date DESC';
$where = null; // so we can concatenate without error
foreach ($inputs as $dbfield=>$formfield) {
if (isset($_POST[$formfield]) and ! empty($_POST[$formfield])) {
// you only need AND if $where has been added to once
if ($where) { $where .= ' and'; }
$where .= " $dbfield='" . mysql_real_escape_string($_POST[$formfield]) . "'"
}
}
//
$query = "select * from classifieds";
if ($where) { $query .= " where $where"; }