簡體   English   中英

需要有關MySQL查詢的幫助

[英]Need help for mysql queries

前三個查詢工作正常,但最后一個則不能。 第二個查詢可以正常使用$status !== ''但最后一個查詢具有相同的$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** 

}
select * from tblquiz where qstatus= '$status' 

qstatus缺少引號嗎?

在您的elseif子句中,檢查$ status為空,然后將其設置為$ querystring和$ countstring。 這意味着您嘗試查詢

qstatus= AND

這應該會產生一個SQL錯誤。 嘗試調試時,打印出sql語句始終是一個好主意。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM