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."</br>");
echo($color."</br>");
echo($caizhi."</br>");
echo($style."</br>");
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{
?>
<td align='right'><div align='center'><?php echo $row['psp_name'];?></div></td>
<? }while($row=mysql_fetch_array($rows));
}
else
{?>
<td align='right'><div align='center'>没有符合条件的信息,请重新定义搜索条件!</div></td>
<?
}
?>