值startlat,startlon,endlat,endlon在我的查詢字符串中顯示爲來自simplexml對象的字段名稱。無法從Simplexml發送lat/lng到mysql數據庫
我打印出來的查詢字符串,看看第3,第4,第5和第6個值
insert into *database.table* (mwayname, sectionname, startlat, startlon, endlat,endlon,avgspd,avgocc,totvol,seclength,sectime)VALUES ('AKL-SH1-NB-RNM' , '1-NB PAPAKURA OFF to PAPAKURA ON' , '->latitude', '->longitude' , '->latitude' , '->longitude' ,'98.7012505914656' , '3.0' , '12.0' , '0.309545' , '0.18817086803564703')
它發送simplexml->到查詢的文本中,還有其他價值,也數值不受影響??當然不是因爲查詢構造函數在循環中?
$xml = new SimpleXMLElement($response);
foreach($xml->return as $return)
{
echo '**********************',$return->name.'*****<br>';
echo '**********************',$return->reference.'*****<br>';
foreach($return->segments as $segments)
{
echo $return->name.'<br>';
echo $return->reference.'<br>';
echo $segments->carriagewaySegmentId.' ID <br>';
echo 'section name ',$segments->sectionName.'<br>';
echo 'start lat ',$segments->startLocation->latitude.'<br>';
echo 'start lng ',$segments->startLocation->longitude.' <br>';
echo 'end lat ',$segments->endLocation->latitude.'<br>';
echo 'end long ',$segments->endLocation->longitude.'<br>';
echo 'avg speed = ',$segments->averageSpeed. ' kmh avg<br>';
echo $segments->averageOccupancy. ' % of rd occupied<br>';
echo $segments->totalVolume. ' traffic volume<br>';
echo $segments->sectionLength. ' km<br>';
echo $segments->sectionTime. ' minutes<br>';
echo'<br>';
//send to mysql
$query = "insert into trafficstats.master (mwayname, sectionname, startlat, startlon, endlat,endlon,avgspd,avgocc,totvol,seclength,sectime)VALUES ('$return->reference' , '$segments->sectionName' , '$segments->startLocation->latitude', '$segments->startLocation->longitude' , '$segments->endLocation->latitude' , '$segments->endLocation->longitude' ,'$segments- >averageSpeed' , '$segments-
>averageOccupancy' , '$segments->totalVolume' , '$segments->sectionLength' , '$segments->sectionTime')";
echo $query;
mysql_query($query);
}
}
?>
在'$ query'中,試試這個:''「。$ segments-> startLocation-> latitude。」''。過去我曾經遇到過類似的問題,突破外線似乎對我有用。 – Dave 2013-03-28 06:53:28
謝謝!它工作:) – user1637477 2013-03-28 07:14:28