PHP multi-Conditional append query

Source: Internet
Author: User
PHP Multi-Conditional overlay Query
 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
{?>
There is no qualifying information, please redefine the search criteria!
}
?>


Does this code have a problem with horses? Why error: Warning:mysql_fetch_array () expects parameter 1 to be resource, boolean given In/data/home/hmu069081/htdocs/prod Ucts/get_post.php on line 37
And there are no eligible information, but the conditions I chose are clearly recorded.
------Solution--------------------
Put all shapes as
$q = $q + "and Psp_brand in (". $brand. ")";
Such a statement, which is shaped like this
$q = $q. "And Psp_brand in (". $brand. ")";
Or
$q. = "and Psp_brand in (". $brand. ")";
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.