php - 访问 MySQL 查询的各个部分

标签 php mysql

如何访问 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/

相关文章:

mysql - C#/SQL 连接问题

mysql - 使用 Sequelize 排除空关联数组

javascript - 如何在页面刷新之间保留变量的值?

php - AMPHP - 排队的任务多于池中可用的工作人员

php - 使用多个搜索词进行搜索

php - laravel artisan 使用未定义的常量 STDIN - 假设 'STDIN' 无限循环

php - 发布数组并重定向到另一个页面

Mysql Switch case 返回不正确的结果

php - Laravel 4 种子数据库表与关系

mysql - MariaDB 客户端默认使用 UTF-8