php - 从mysql查询结果数组访问信息?

标签 php mysql

我查看了官方文档,但我似乎仍然无法访问自变量,例如“城市”。在 sql 查询之后,我使用 $results[0] 来获取它。我如何访问“城市”?

   $results =  DB::table('users')->get();

    birthdate = "0000-00-00 00:00:00";
    city = "Laguna Hills";
    country = "<null>";
    "created_at" = "2014-07-21 07:11:06";
    email = "sammy0@gmail.com";
    id = 1;
    "is_verified" = "<null>";
    "location_lat" = "<null>";
    "location_lon" = "<null>";
    password = RightNow25;
    "updated_at" = "0000-00-00 00:00:00";
    username = sammy0;
    zip = "<null>";

最佳答案

尝试使用“print_r”将完整输出打印到页面(请参阅下面的代码)。它非常有用,因为您可以查看数组中的所有元素及其键和值。

//(using print_r between '<pre>' and '</pre>' formats the data to a human readable format)


print '<pre>';
print_r($results);
print '</pre>';

这应该有助于确定您的数据是否按预期返回。

关于php - 从mysql查询结果数组访问信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24864622/

相关文章:

sql - 基于列顺序的查询速度

php - mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows 等...期望参数 1 是资源

php - Cookies/ session 登录系统

php - 尝试输出时调用未定义函数 session_unregister()

Javascript 隐藏按钮

MySQL 无法比较文本

mysql 匹配多个and 和or

php - 如何制作缩放工具来像谷歌地图一样缩放图像?

php - 从带有空格和换行符的 MySQL 数据库回显?

php - 如何使用 PHP 从 URL 获取域名?