繁体   English   中英

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

[英]Accessing information from mysql query results array?

我查看了官方文档,但似乎仍然无法访问自变量,例如“ city”。 在执行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>';

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM