不管用什么条件检索,结果只有一条SQL查询语句。
关键字填写了的查询,用 and 连接上就是了。

解决方案 »

  1.   

    一个一个判断
    var sql="...... whrer 1 = 1";   
    if(性别不为空)
    {
    sql += " and sex=sex";
    }
    if(爱好不为空)
    {
    sql+= "and 爱好 = 爱好";
    }这样一个个来
      

  2.   

    谢谢楼上,但我在写SQL时总得加上条件是吧,如果按姓名 where 姓名 like xxx ,那如果姓名为空,或期它条件为空怎么办呢?
      

  3.   

    sql语句只需要一条,但是where子句是要用多个if来组织起来的.例如
    $Where = " where 1 ";
    if($_POST['name']<>"")
        $Where = " and name like '%".$_POST['name']."%'";
    if(...)
        $Where = " and ..........";最后把这个Where 子句接在sql语句上并加排序或分页就可以了
    $sql = "Select ... from ... ".$Where." order by .. limit .."
      

  4.   

    if(性别不为空)
    {
    sql += " and sex=sex";
    }
    看到没有啊..如果不为空才+
    如果为空它根本不会+啊..