php多条件怎么查找,php多条件附加查询

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{

?>

    }while($row=mysql_fetch_array($rows));

}

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.")";

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值