2

如何访问我的 mysql_query 的特定部分?我正在尝试使用下面的代码执行此操作,但无济于事。非常感激任何的帮助!

$rs = mysql_query("SELECT id,type FROM stuff WHERE stuffID = '$stuffID'");

   echo $rs['type']; <------ tried here

   // Add the rows to the array 
   while($obj = mysql_fetch_object($rs)) {
   $arr[] = $obj;
   }
 echo $arr['type']; <----- also tried here
4

1 回答 1

3

在获取该行之前,您无法访问该行。

while($obj = mysql_fetch_object($rs)) {
    // NOTE: $arr[] = $obj, is the same as array_push($arr, $obj),
    // I dont think you want that
    $arr = $obj; // save the row

    echo $obj->type; // you are fetching an object, not an array
}

echo $arr->type;  // you can access it here too
于 2012-08-21T18:41:59.330 回答