gpt4 book ai didi

php - 无法将 lat/lng 从 Simplexml 发送到 mysql 数据库

转载 作者:行者123 更新时间:2023-11-29 05:30:12 25 4
gpt4 key购买 nike

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

最佳答案

试试这个查询

$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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com