如何访问 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
最佳答案
在获取该行之前,您无法访问该行。
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
关于php - 访问 MySQL 查询的各个部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12061046/