【问题标题】:View all mysql data in InfoWindows gmap在 InfoWindows gmap 中查看所有 mysql 数据
【发布时间】:2013-01-04 12:48:17
【问题描述】:

下面的脚本有问题,如何将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);
    });

}

【问题讨论】:

    标签: php mysql ajax gis


    【解决方案1】:

    你有几个问题需要解决:

    1. 您的 php 脚本没有返回有效的 json。您应该将所有数据收集在一个变量中,最后执行echo json_encode($your_data); 之类的操作
    2. 您从 mysql 获取的数据与您在 javascript 中使用的变量之间似乎没有任何关系:您的 javascript 变量名称暗示了您刚刚获得 NameAddress 的数组/对象的嵌套结构从数据库。如果您希望结果包含 msg.wilayah.petak[i].deskripsi 之类的内容,则需要先在 php 中生成正确的结构。

    并且你有一个sql注入错误,你应该切换到PDO(或mysqli)并使用绑定变量准备语句。

    【讨论】:

    • 感谢您的回答,我只想在 infowindows 中显示脚本--> judulx[i] desx[i]。但我不能。你能给我正确的剧本吗?或示例。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-19
    • 2011-02-10
    • 1970-01-01
    • 2011-12-10
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多