我使用此代码在google地图中显示信息窗口
 var infoWindow = new google.maps.InfoWindow({
    position: latlng,
    content: 'Hello, world'
  });我有一个php代码来从数据库中检索地址。
<?php
mysql_connect("localhost", "root", "root") or die (mysql_error ());
mysql_select_db("theaterdb") or die(mysql_error());
$strSQL =("SELECT address FROM theaters WHERE theater_name='" . mysql_real_escape_string($_POST['course']) . "'");
$rs = mysql_query($strSQL);
while($row = mysql_fetch_array($rs)) {
echo "<b>Theater Address:</b><br>";
echo $row['address'] . "<br /><br />";
 }
 mysql_close();
?>现在我需要从数据库中获取地址到infowindow的content field..how才能做到这一点?任何人都可以提前帮助me....thanks。
发布于 2012-09-26 20:58:14
使用mysql_fetch_assoc()并分配$row数据库值:
<?php
    $link = mysql_connect("localhost", "root", "root") or die (mysql_error());
    mysql_select_db("theaterdb", $link) or die(mysql_error());
    $strSQL = "SELECT address FROM theaters WHERE theater_name='" . mysql_real_escape_string($_POST['course']) . "'";
    $rs = mysql_query($strSQL);
    $row = mysql_fetch_assoc($rs);
    mysql_close();
?>
<script>
  var infoWindow = new google.maps.InfoWindow({
    position: latlng,
    content: '<b>Theater Address:</b><br> <?php echo $row['address']; ?>'
  });
</script>需要注意的是,当mysql_*函数被弃用时,您可以尝试将您的代码移动到PDO,请查看这个不错的tutorial。
https://stackoverflow.com/questions/12602160
复制相似问题