简体   繁体   English

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

[英]Accessing information from mysql query results array?

I looked at the official documentation,but I still can't seem to access the independent variables for example "city". 我查看了官方文档,但似乎仍然无法访问自变量,例如“ city”。 After a sql query, I use $results[0] to get this. 在执行SQL查询后,我使用$ results [0]来获取此信息。 How can I access "city"? 如何访问“城市”?

   $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>";

Try printing the full output to the page using 'print_r' (see the below code). 尝试使用'print_r'将全部输出打印到页面上(请参见下面的代码)。 It is very useful since you can see all elements within the array along with they keys and values. 这非常有用,因为您可以看到数组中的所有元素以及它们的键和值。

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


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

This should help to identify if your data is being returns as intended. 这应该有助于确定是否按预期返回了您的数据。

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

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