簡體   English   中英

SQL無法正常工作? 它也不會出現錯誤

[英]SQL won't work? It doesn't come up with errors either

我有PHP函數,該函數檢查是否設置了變量,然后將其添加到我的SQL查詢中。 但是我似乎沒有得到任何結果嗎?

 $where_array = array();
   if (array_key_exists("location", $_GET)) {
       $location = addslashes($_GET['location']);
       $where_array[] = "`mainID` = '".$location."'";
   }
   if (array_key_exists("gender", $_GET)) {
       $gender = addslashes($_GET["gender"]);
       $where_array[] = "`gender` = '".$gender."'";
   }
   if (array_key_exists("hair", $_GET)) {
       $hair = addslashes($_GET["hair"]);
       $where_array[] = "`hair` = '".$hair."'";
   }
   if (array_key_exists("area", $_GET)) {
       $area = addslashes($_GET["area"]);
       $where_array[] = "`locationID` = '".$area."'";
   }

   $where_expr = '';
   if ($where_array) {
       $where_expr = "WHERE " . implode(" AND ", $where_array);
   }

   $sql = "SELECT `postID` FROM `posts` ". $where_expr;

   $dbi = new db();
   $result = $dbi->query($sql);
   $r = mysql_fetch_row($result);

我試圖在像這樣的列表中調用數據:

      $dbi = new db();
 $offset = ($currentpage - 1) * $rowsperpage;

 // get the info from the db 
 $sql .=  " ORDER BY `time` DESC  LIMIT $offset, $rowsperpage";
 $result = $dbi->query($sql);
 // while there are rows to be fetched...   

      while ($row = mysql_fetch_object($result)){
          // echo data

        echo $row['text'];


       } // end while

有人知道為什么我不檢索任何數據嗎?

while ($row = mysql_fetch_object($result)){
      // echo data

    echo $row->text;


   } // end while

我忘了它不是來自數組!

暫無
暫無

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

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