开发者

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

I have PHP function which checks to see if variables are set and then adds them onto my SQL query. However I am don't seem to be getting any results back?

 $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);

I'm trying to call the data after in a list like so:

      $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

Anyo开发者_开发百科ne got any ideas why I am not retrieving any data?


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

    echo $row->text;


   } // end while

I forgot it wasn't coming from an array!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜