php多條件附加查詢

來源:互聯網
上載者:User
php多條件疊加查詢
header("Content-Type:text/html;charset=utf-8");
include("../manage/include/function.php");
$brand=substr($_POST["brand"],0,strlen($_POST["brand"])-1);
$color=substr($_POST["color"],0,strlen($_POST["color"])-1);
$caizhi=$_POST["caizhi"];
$style=$_POST["style"];
$kucun=$_POST["kucun"];
echo($brand."
");
echo($color."
");
echo($caizhi."
");
echo($style."
");
echo($kucun);

$q="select * from pros_pro where (1=1)";
if($brand!=null){
$q=$q+"and psp_brand in(".$brand.")";
}
if($color!=null){
$q=$q+"and psp_color in(".$color.")";
}
if($caizhi!=null){
$q=$q+"and psp_caizhi='".$caizhi."'";
}
if($style!=null){
$q=$q+"and psp_style='".$style."'";
}
if($kucun!=null){
$q=$q+"order by psp_stock desc";
}else
{
$q=$q+"order by psp_id desc";
}


$rows=query($q);
if($row=mysql_fetch_array($rows))
{
do{
?>

}
else
{?>
沒有合格資訊,請重新定義搜尋條件!
}
?>


這個代碼有神馬問題?為什麼會報錯:Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /data/home/hmu069081/htdocs/products/get_post.php on line 37
且沒有合格資訊,可是我選的條件明明是有記錄的
------解決方案--------------------
把所有形如
$q=$q+"and psp_brand in(".$brand.")";
這樣的語句,改成形如這樣的
$q = $q ." and psp_brand in(".$brand.")";

$q .= " and psp_brand in(".$brand.")";
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.