我的下面脚本有问题,如何将数据从mysql显示到infowindow?
显示的数据是MySQL中的所有数据。我可以使用以下脚本
$sql=mysql_query("SELECT * FROM map WHERE id='$_get[id]'");
while($sq=mysql_fetch_array($sql)){
echo " Name = $sq[name]";
echo " Address = $sq[address]";
}
显示地图?
以上是我的问题脚本:
function ambildatabase(akhir){
if(akhir=="akhir"){
url = "ambildata.php?akhir=1";
}else{
url = "ambildata.php?akhir=0";
}
$.ajax({
url: url,
dataType: 'json',
cache: false,
success: function(msg){
for(i=0;i<msg.wilayah.petak.length;i++){
judulx[i] = msg.wilayah.petak[i].judul;
desx[i] = msg.wilayah.petak[i].deskripsi;
set_icon(msg.wilayah.petak[i].jenis);
var point = new google.maps.LatLng(
parseFloat(msg.wilayah.petak[i].x),
parseFloat(msg.wilayah.petak[i].y));
var tanda = new google.maps.Marker({
position: point,
animation: google.maps.Animation.BOUNCE,
map: peta,
icon: gambar_tanda
});
setinfo(tanda,i);
}
}
});
}
这是内容的地方:
var infowindow = new google.maps.InfoWindow({
content: "asdasdasd"
});
function setinfo(petak, nomor){
google.maps.event.addListener(petak, 'click', function() {
infowindow.open(peta,petak);
});
}
答案 0 :(得分:0)
您需要解决一些问题:
echo json_encode($your_data);
Name
和{来自数据库的{1}}。如果您希望结果包含Address
之类的内容,则需要先在php中生成正确的结构。你有一个sql注入错误,你应该切换到PDO(或mysqli)并准备带有绑定变量的语句。