|
|
|
| поиск по селектам
<?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' ";
$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());
|
| |
|
|
|
|
|
|
|
для: mark1
(19.10.2009 в 00:16)
| | И какой ответ вы получаете?
Заодно покажите, какой запрос у вас получается в результате (переменную $sql перед запрсов на экран выведите) | |
|
|
|
|
|
|
|
для: neadekvat
(19.10.2009 в 00:28)
| | выдает ошибку
Ошибка извлечения данных You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'A' at line 1 | |
|
|
|
|
|
|
|
для: mark1
(19.10.2009 в 00:38)
| | >выдает ошибку
>Ошибка извлечения данных You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'A' at line 1
Видимо ND оно удалило, а А нет. В запросе ошибка только в 'A', ясно же написано с какого символа пошло нарушение синтаксиса. | |
|
|
|
|
|
|
|
для: mark1
(19.10.2009 в 00:16)
| | вот этот AND здесь не лишний?
if ($mat_id !== "") $where_mat_id = " mat_id = '$mat_id' AND "; | |
|
|
|
|
|
|
|
для: Рома
(19.10.2009 в 01:35)
| | лишний,но он вот так убирается
$sql = substr_replace($sql, ' ', -4); | |
|
|
|
|
|
|
|
для: Рома
(19.10.2009 в 01:35)
| | если так оставить
$sql = substr_replace($sql, ' ', -5);
ошибку не выдает но в базе не ищет | |
|
|
|