值starttat、startton、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);
}
}
?>

最佳答案

尝试此查询

$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."')";

关于php - 无法将Lat/Lng从Simplexml发送到mysql数据库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15675820/

10-11 03:18