由于没有学过PHP,所以只有写伪代码了:
不知道 isdelete=0 是什么作用,暂时没加
sql语句初始为 select * from thread where ''=''if(title不为空){
     sql语句加上 ' and title='+title的值
}
if(content不为空){
     sql语句加上 ' and content='+content的值
}
if(author不为空){
     sql语句加上 ' and author='+author的值
}执行sql

解决方案 »

  1.   

    <?
    $sql = "select * from ";
    $tem = "";if($_POST['title']){
     $tem.=(empty($tem)?" WHERE":" AND")."title = '".$_POST['title']'"'";
    }
    if($_POST['content']){
     $tem.=(empty($tem)?" WHERE":" AND")."content = '".$_POST['content']'"'";
    }
    if($_POST['author']){
     $tem.=(empty($tem)?" WHERE":" AND")."author = '".$_POST['author']'"'";
    }empty($tem)?($sql." WHERE isdelete = 0"):($sql.$tem." and isdelete = 0");
    ?>
      

  2.   

    上面有错误.因该是
    $sql = "select * from thread ";
      

  3.   

    你的需求是如何组装查询串假定表单提交的变量名与数据表中对应字段同名,则$w = array();
    foreach($_POST as $k=>$v) {
      if(! empty($v)) {
        $w[] = "$k='$v'";
      }
    }
    if(count($w) < 1) {
      die('至少应输入一个条件');
    }
    $exec="select * from thread where isdelete=0 and " . join(' and ', $w);  
      

  4.   

    哈哈,老大的确厉害..
    既然楼主还要想更简单的方法,,,可以直接这样写:select * from thread where isdelete=0 and title ='".$title."' and content ='".$content."'  ...    记得有单引号!
    这样,,,如果输入为空的话MYSQL也找不到结果!
    将语句留给MYSQL去判断~!