本文介绍了获取数据库的值并将其传输到Leaflet POP UP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
美好的一天!我只是想问一个小问题。啊,你如何显示从数据库到传单的数据弹出?
这是我在php select命令中的代码
Good Day too all! I just wanna ask a little question. Ahmm how do you show data from database to leaflet pop up?
Here is my code in php select command
<?php
$db = new PDO('mysql:host=localhost;dbname=poi', 'root', '');
$sql = "SELECT name,user_date,user_time,address,lat,lng,icon_name FROM tblmarker";
$rs = $db->query($sql);
if (!$rs) {
echo "An SQL error occured.\n";
exit;
}
$rows = array();
while($r = $rs->fetch(PDO::FETCH_ASSOC)) {
$rows[] = $r;
$name[] = $r['name'];
$user_date[] = $r['user_date'];
$user_time[] = $r['user_time'];
$address[] = $r['address'];
$icon_name[] = $r['icon_name'];
}
print json_encode($rows);
$db = NULL;
?>
这是我在数据库中显示地图标记的代码
and here is my code in showing the marker in the map from database
function getInfo() {
$.getJSON("get_info.php", function (data) {
for (var i = 0; i < data.length; i++) {
var location = new L.LatLng(data[i].lat, data[i].lng);
var marker = new L.Marker(location,{icon:Icon1});
var ll = marker.getLatLng();
marker.bindPopup("$name<br>$user_date<br>$user_time<br>$address<br>$icon_name").addTo(map);
}
});
}
我认为它有效,因为当我刷新它时,我的数据库中的标记显示在地图中,但是当我点击标记弹出时弹出up show只有这样。
I thought it works because when i refresh it the marker from my database shows in the map but when i click the marker for the pop up the pop up shows only is like this.
$name
$user_date
...
我的代码有什么问题?我错过了什么吗? TYFH和IA
...
Whats wrong with my code? Am I missing something? TYFH and IA
推荐答案
这篇关于获取数据库的值并将其传输到Leaflet POP UP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!