Home  >  Article  >  Backend Development  >  php多条件外加查询

php多条件外加查询

WBOY
WBOYOriginal
2016-06-13 11:45:08817browse

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
且没有符合条件的信息,可是我选的条件明明是有记录的

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn