при поиске по селектам,надо если заполнены не все поля искать по ним
<?php
if (isset($_POST['cat'])) $cat_id = $_POST['cat'];
if (isset($_POST['city'])) $city_id = $_POST['city'];
if (isset($_POST['komnati'])) $kom_id = $_POST['komnati'];
if (isset($_POST['sdelka'])) $sd_id = $_POST['sdelka'];
if (isset($_POST['planirovka'])) $plan_id = $_POST['planirovka'];
if (isset($_POST['material'])) $mat_id = $_POST['material'];
$where_cat_id = " cat_id = '$cat_id' "; // в таблице data поле cat_id,созлаем для нее переменную
$where_city_id = " city_id = '$city_id' ";
$where_kom_id = " kom_id = '$kom_id' ";
$where_sd_id = " sd_id = '$sd_id' ";
$where_plan_id = " plan_id = '$plan_id' ";
$where_mat_id = " mat_id = '$mat_id' ";
if ($сat_id !== "") $where_cat_id = " cat_id = '$cat_id' AND ";
else $where_cat_id == "";
if ($city_id !== "") $where_city_id = " city_id = '$city_id' AND ";
else $where_city_id == "";
if ($kom_id !== "") $where_kom_id = " kom_id = '$kom_id' AND ";
else $where_kom_id == "";
if ($sd_id !== "") $where_sd_id = " sd_id = '$sd_id' AND ";
else $where_sd_id == "";
if ($plan_id !== "") $where_plan_id = " plan_id = '$plan_id' AND ";
else $where_plan_id == "";
if ($mat_id !== "") $where_mat_id = " mat_id = '$mat_id' AND ";
else $where_mat_id == "";
if($_POST['action']=="search")
{
$sql = "SELECT * FROM data ";
if (($where_cat_id !== "")||($where_city_id !== "")||($where_kom_id !== "")||($where_sd_id !== "")||($where_plan_id !== "")||($where_mat_id !== "")) $sql .= " WHERE ";
$sql .= " " . $where_cat_id . " ";
$sql .= " " . $where_city_id . " ";
$sql .= " " . $where_kom_id . " ";
$sql .= " " . $where_sd_id . " ";
$sql .= " " . $where_plan_id . " ";
$sql .= " " . $where_mat_id . " ";
$sql = substr_replace($sql, ' ', -4);
$res = mysql_query($sql);
if(!$res) exit("Ошибка извлечения данных ".mysql_error());
(Отредактировано автором: 19 Октября, 2009 - 00:24:42)