可以整理SQL的语句,如把WHERE语句先独立成$sql_where,假设生成了字符串:
"and  '$agexiao'< age and age < '$ageda'",可以用substr()函数整理,如:
substr($sql_where,4)就可以得到"'$agexiao'< age and age < '$ageda'".

解决方案 »

  1.   


    $sql = "select * from base where 0=0 ";
    if($sex !="都可以")
    {
       $sql = $sql."and  where Xingbie='$sex'";
    }if($xuelid!="都可以")
    {
    $sql = $sql."and Xueli = '$xuelid'";
    }if($agexiao!="都可以" and $ageda!="都可以")
    {
    $sql=$sql."and  '$agexiao'< age and age < '$ageda'";     }
      

  2.   

    第三行的where去掉,还要注意一点就是多用一些空格不然你sql语句会粘在一起。
      

  3.   

    $sql = "select * from base where 1=1";
    if($sex !="都可以")
    {
       $sql = $sql." and Xingbie='$sex'";
    }if($xuelid!="都可以")
    {
    $sql = $sql." and Xueli = '$xuelid'";
    }