基本上我正在创建一个从数据库中提取信息的动态谷歌地图,连接很好,查询很好 - 但我无法从我的函数访问我的变量($row)。
我应该从 php 函数本身解析所有 javascript 吗?或者我可以让它在我的页面上静态并通过直接在 javascript 上方调用函数 (getCurrentMapData) 来访问变量?
function getCurrentMapData( $select )
{
global $mysqli;
$sql = $mysqli->query($select);
if(!$sql) {
printf("%s\n", $mysqli->error);
exit();
}
$row = $sql->fetch_array();
}
这是我们的开始:
<?php
$select = "SELECT `id`, `title`, `address`, `lat`, `lng`, `date` FROM `globalmap` ORDER BY `id` desc ";
getCurrentMapData( $select );
?>
<h3>
I'm Currently Playing @
<?php echo $row['title'] ?>
</h3>
<div id="map">
<div id="ps_map_1" class="mapCon">
</div>
</div>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script> <script>
// <![CDATA[
var psGlobals = {
address: "<?php echo $row['address'] ?>",
lat: <?php echo $row['lat'] ?>,
lon: <?php echo $row['lng'] ?>,
zoomlevel: 13
};
function initialize()
{
psGlobals.latlng = new google.maps.LatLng(psGlobals.lat, psGlobals.lon);
buildMap();
psGlobals.dirRenderer = new google.maps.DirectionsRenderer();
psGlobals.dirService = new google.maps.DirectionsService();
}
function buildMap()
{
var myOptions, marker;
myOptions = {
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.ZOOM_PAN
},
mapTypeControl: true,
scaleControl: false,
zoom: psGlobals.zoomlevel,
center: psGlobals.latlng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
psGlobals.map = new google.maps.Map(document.getElementById("ps_map_1"), myOptions);
psGlobals.marker = new google.maps.Marker({
position: psGlobals.latlng,
map: psGlobals.map,
title: "<?php echo $row['title'] ?>"
});
}
$(document).ready(function(){
initialize()
});
// ]]>
</script>