从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>';

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