Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: помогите исправить ошибку
Форумы портала PHP.SU » PHP » Напишите за меня, пожалуйста » помогите исправить ошибку

Страниц (1): [1]
 

1. mark1 - 18 Октября, 2009 - 23:56:52 - перейти к сообщению
при поиске по селектам,надо если заполнены не все поля искать по ним
<?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());
2. koras - 19 Октября, 2009 - 00:04:02 - перейти к сообщению
Код не читабельный и смайлы уберите.
3. Viper - 19 Октября, 2009 - 08:34:38 - перейти к сообщению
Цитата:
$where_cat_id == "";


это вообще зачем ? вы же не проверку в if делаете, а присваиваете значение переменной.

 

Powered by ExBB FM 1.0 RC1