0
我想存儲我的結果只是位置名稱,我發現結果作爲一個數組,但它不能存儲在我的數據庫中,它只打印名稱'數組'數據庫發送打印結果到我的數據庫作爲字符串
try {
$user6 = $fb->get('/me?fields=location');
$user6 = $user6->getGraphNode()->asArray();
//echo $user6->location->name;
$user6->location->name;
echo "<pre/>";print_r($user6);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
session_destroy();
// if access token is invalid or expired you can simply redirect to login page using header() function
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
爲了拯救我的結果在我的DATABSE,我的代碼如下:
$location= $user6 ['location'];
echo $location;
mysql_query("insert into newmember(location) values('$location')") or die(mysql_error());
我的結果是:
Array
(
[location] => Array
(
[id] => 101889586519301
[name] => Dhaka, Bangladesh
)
[id] => 1589273127757008
)
什麼是'$ location'的價值? –
我的結果是低於實際我想保存它只有位置「孟加拉國」。陣列 ( [位置] =>數組 ( [ID] => 101889586519301 [名稱] =>孟加拉國達卡 ) [ID] => 1589273127757008 ) – Nayan
嘗試$位置= $ user6 ['位置']['名稱']; –