如何访问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
答案 0 :(得分: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