[英]Inserting MySQL variables into Google maps with PHP
Can anybody see why code 1 works but code 2 doesn't? 有人能看到为什么代码1有效但代码2无效吗? its driving me crazy!!!
这让我疯狂!!!
CODE 1: 代码1:
<?PHP
$con=mysqli_connect("a","b","c","d");
$result = mysqli_query($con,"SELECT * FROM map_places");
while($row = mysqli_fetch_array($result))
{
$lat2=$row['latitude'];
$lon2=$row['longitude'];
echo 'var myLatLng = new google.maps.LatLng('.$lat2.','.$lon2.');';
echo 'var myMarker = new google.maps.Marker({';
echo 'position: myLatLng,';
echo 'map: map,';
echo '});';
}
?>
CODE 2: 代码2:
<?PHP
$con=mysqli_connect("a","b","c","d");
$min = (int)$_POST['min'];
$sql = "
SELECT map_places.latitude, map_places.longitude
FROM map_places
INNER JOIN map_items ON (map_items.host_id = map_places.id)
WHERE map_items.value >".$min."
GROUP BY map_places.id
";
$result1 = mysqli_query($con,$sql);
while($row1 = mysqli_fetch_array($result1));
{
$lat1=$row1['latitude'];
$lon1=$row1['longitude'];
echo 'var myLatLng = new google.maps.LatLng('.$lat1.','.$lon1.');';
echo 'var pokerMarker = new google.maps.Marker({';
echo 'position: myLatLng,';
echo 'map: map,';
echo '});';
}
?>
They are essentially the same code with code 1 pulling all of the data and posting it onto a Google map and code 2 pulling certain data (all that have a value higher than $min) and putting it on a Google map, I have put the select through MySQL and it pulls the correct data, however if I use (int) on $row1... and $row2... the lat long values posted on my map are 0,0. 它们本质上是相同的代码,其中代码1提取所有数据并将其发布到Google地图上,代码2提取某些数据(所有值均高于$ min的数据)并将其放入Google地图上,我将通过MySQL选择,它会提取正确的数据,但是,如果我在$ row1 ...和$ row2 ...上使用(int),则在我的地图上发布的经纬度值为0,0。 Can anybody explain why this happens?
谁能解释为什么会这样? (all code outside what I have posted is the same for code 1 and code 2 and as code 1 works my problem should lie somewhere here).
(我发布的内容之外的所有代码对于代码1和代码2都是相同的,并且随着代码1的工作,我的问题应该在这里。) Thank you for any help trying to get code 2 to work has been driving me crazy for days!!
感谢您为使代码2正常工作所提供的任何帮助,这使我发疯了好几天了!
while($row1 = mysqli_fetch_array($result1));
remove the ; 去除 ; at the end of the line
在行尾
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.