需要帮助mysql查询

时间:2012-09-01 02:18:50

标签: php mysql

前三个查询工作正常,但最后一个查询没有。第二个查询正常工作$status !== ''但最后一个查询具有相同$status !== ''不执行查询可以帮助我任何人

if (isset($_POST['go'])) {

     $status = $_POST[status];
     if ($status == 4){
             $status = '' ;
     }

    if ($topic == 100 && $subtopic == '' && $status == '' ) {
    $queryString = "select * from tblquiz where userid='$_SESSION[numericuserid]' LIMIT $start, $limit" ;
    $countString = "select * from tblquiz where userid='$_SESSION[numericuserid]'";
    }  // NOTE : THIS QUERY IS WORKING PERFECT

       elseif ($topic !== '' && $subtopic !== '' && $status !== '' ) {
    $queryString = "select * from tblquiz where qstatus=$status AND  qtopic='$topic[topicname]' AND subtopic='$_POST[subtopic]' AND userid='$_SESSION[numericuserid]' LIMIT $start, $limit" ;
    $countString = "select * from tblquiz where qstatus=$status AND  qtopic='$topic[topicname]' AND subtopic='$_POST[subtopic]' AND      userid='$_SESSION[numericuserid]'";
       }  // NOTE : THIS QUERY IS WORKING PERFECT

       elseif ($topic !== '' && $subtopic !== '' && $status == '' ) {
    $queryString = "select * from tblquiz where   qtopic='$topic[topicname]' AND subtopic='$_POST[subtopic]' AND userid='$_SESSION[numericuserid]' LIMIT $start, $limit" ;
    $countString = "select * from tblquiz where   qtopic='$topic[topicname]' AND subtopic='$_POST[subtopic]' AND userid='$_SESSION[numericuserid]'";
       }  // NOTE : THIS QUERY IS WORKING PERFECT


       elseif  ($topic == 100 && $subtopic == '' && $status !== '') {
    $queryString = "select * from tblquiz where qstatus= $status AND userid='$_SESSION[numericuserid]' LIMIT $start, $limit" ;
    $countString = "select * from tblquiz where qstatus= $status AND userid='$_SESSION[numericuserid]' ";
     }  **// NOTE : THIS QUERY IS NOT WORKING** 

}

2 个答案:

答案 0 :(得分:0)

select * from tblquiz where qstatus= '$status' 

qstatus缺少引号?

答案 1 :(得分:0)

在你的elseif子句中,你检查$ status是否为空,如果是,则设置$ querystring和$ countstring。这意味着您尝试查询

qstatus= AND

这应该会产生SQL错误。在尝试调试时打印出你的sql语句总是一个好主意。