2014-07-21 38 views
0

我看了官方文檔,但我仍然無法訪問自變量,例如「城市」。在sql查詢之後,我使用$ results [0]來獲取它。我怎樣才能訪問「城市」?從MySQL查詢結果數組中訪問信息?

$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 = "[email protected]"; 
    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>"; 
+1

$ results [0] ['city']? – t3chguy

回答

0

嘗試使用'print_r'(請參閱下面的代碼)將完整輸出打印到頁面。這非常有用,因爲您可以看到陣列中的所有元素以及它們的鍵和值。

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


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

這應該有助於確定您的數據是否按預期返回。