值 startlat,startlon,endlat,endlon 在我的查询字符串中显示为来自 simplexml 对象的字段名称。
我打印出查询字符串,查看第 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);
}
}
?>