0
我想隱藏的谷歌地圖如果SQL失敗:谷歌地圖是始終顯示
$result = mysql_query("SELECT melding FROM alarmeringen2010 WHERE `date1` >= DATE_ADD(NOW(), INTERVAL -15 MINUTE)");
$row = mysql_fetch_row($result);
if ($result) {
?>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&language=nl"></script>
<script> var directionsDisplay; var directionsService = new google.maps.DirectionsService(); function initialize() { directionsDisplay = new google.maps.DirectionsRenderer(); var mapOptions = { zoom: 7, center: new google.maps.LatLng(52.7100647, 5.2716885) }; var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); directionsDisplay.setMap(map); directionsDisplay.setPanel(document.getElementById('directions-panel')); var start = document.getElementById('start').value; var end = '<?php echo $row[0]; ?>'; var request = { origin: start, destination: end, travelMode: google.maps.TravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); } google.maps.event.addDomListener(window, 'load', initialize); </script>
<div style="width:70%;height:600px;">
<div id="control" style="margin-left:-30000px">
<select id="start" onchange="calcRoute();">
<option value="gerard brandweg 3 enkhuizen, nederland">enkhuizen</option>
</select>
<select id="end" onchange="calcRoute();">
<option value="<?php echo $row[0]; ?>, nederland">enkhuizen</option>
<option value="<?php echo $row[0]; ?>, nederland">enkhuizen</option>
</select>
</div>
<div id="directions-panel"></div>
<div id="map-canvas"></div>
</div>
<?php
};?>
if語句仍在加載HTML和腳本時失敗。
'$ result'可以intepreted爲TRUE,如果查詢不會失敗。你可以使用'mysql_num_rows($ result)'知道返回的行數。 但是,請使用mysqli_ * API而不是mysql_已棄用 – Marcassin
失敗與返回0行不一樣。你究竟是什麼意思?你可能想'if($ row)'。 – jeroen
@ jeroen謝謝你這就是我想要的。現在它是固定的 – 810