php多条件叠加查询
<?<br /> header("Content-Type:text/html;charset=utf-8");<br /> include("../manage/include/function.php");<br /> $brand=substr($_POST["brand"],0,strlen($_POST["brand"])-1); <br /> $color=substr($_POST["color"],0,strlen($_POST["color"])-1); <br /> $caizhi=$_POST["caizhi"];<br /> $style=$_POST["style"];<br /> $kucun=$_POST["kucun"];<br /> echo($brand."</br>");<br /> echo($color."</br>");<br /> echo($caizhi."</br>");<br /> echo($style."</br>");<br /> echo($kucun);<br /> <br /> $q="select * from pros_pro where (1=1)";<br /> if($brand!=null){<br /> $q=$q+"and psp_brand in(".$brand.")";<br /> }<br /> if($color!=null){<br /> $q=$q+"and psp_color in(".$color.")";<br /> }<br /> if($caizhi!=null){<br /> $q=$q+"and psp_caizhi='".$caizhi."'";<br /> }<br /> if($style!=null){<br /> $q=$q+"and psp_style='".$style."'";<br /> }<br /> if($kucun!=null){<br /> $q=$q+"order by psp_stock desc";<br /> }else<br /> {<br /> $q=$q+"order by psp_id desc";<br /> }<br /> <br /> <br /> $rows=query($q);<br /> if($row=mysql_fetch_array($rows))<br /> {<br /> do{<br /> ?><br /> <td align='right'><div align='center'><?php echo $row['psp_name'];?></div></td><br /> <? }while($row=mysql_fetch_array($rows));<br /> }<br /> else<br /> {?><br /> <td align='right'><div align='center'>没有符合条件的信息,请重新定义搜索条件!</div></td><br /> <?<br /> }<br /> ?>