2015-06-19 71 views
-2

我試圖通過從我的數據庫獲取緯度和經度來顯示點,而查詢是(SELECT * FROM trackEmployee)它正在檢索 數據並在地圖上顯示它(Y)將變量從php標記傳遞給同一頁中的其他標記

但是,當我試圖通過獲取POST數據來設定條件WHERE groupEmail ='$mail' AND date= '$date'它不工作

如果我直接值傳遞給的條件下,它的工作原理(Y)

問題這裏是從上面的php標籤獲取數據到下一個包含查詢的php標籤。

<html> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
<title>Google Map API V3 with markers</title> 
<style type="text/css"> 
body { font: normal 10pt Helvetica, Arial; } 
#map { width: 750px; height: 400px; border: 0px; padding: 0px; } 
</style> 

<?php 


$connect_mysql= @mysql_connect($server,$username,$passwor) or die ("Connection Failed!"); 
$mysql_db=mysql_select_db("GP15",$connect_mysql) or die ("Could not Connect to Database"); 

$mail=$_POST['sel1']; 
echo $mail; // prints correctly 
$date=$_POST['sel2']; 
echo $date; // prints correctly 

//On page 2 
?> 

<script src="http://maps.googleapis.com/maps/api/js?sensor=false" type="text/javascript"></script> 
<script type="text/javascript"> 
//Sample code written by August Li 
var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png", 
new google.maps.Size(32, 32), new google.maps.Point(0, 0), 
new google.maps.Point(16, 32)); 
var center = null; 
var map = null; 
var currentPopup; 
var bounds = new google.maps.LatLngBounds(); 



function addMarker(lat, lng, info) { 
var pt = new google.maps.LatLng(lat, lng); 
bounds.extend(pt); 
var marker = new google.maps.Marker({ 
position: pt, 
icon: icon, 
map: map 
}); 
var popup = new google.maps.InfoWindow({ 
content: info, 
maxWidth: 300 
}); 
google.maps.event.addListener(marker, "click", function() { 
if (currentPopup != null) { 
currentPopup.close(); 
currentPopup = null; 
} 
popup.open(map, marker); 
currentPopup = popup; 
}); 
google.maps.event.addListener(popup, "closeclick", function() { 
map.panTo(center); 
currentPopup = null; 
}); 
} 
function initMap() { 
map = new google.maps.Map(document.getElementById("map"), { 
center: new google.maps.LatLng(0, 0), 
zoom: 14, 
mapTypeId: google.maps.MapTypeId.ROADMAP, 
mapTypeControl: false, 
mapTypeControlOptions: { 
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR 
}, 
navigationControl: true, 
navigationControlOptions: { 
style: google.maps.NavigationControlStyle.SMALL 
} 
}); 

    <?php 

// $ query = mysql_query(「SELECT * FROM trackEmployee」); //這個查詢工作

$query = mysql_query("SELECT * FROM trackEmployee WHERE employeeEmail='$mail'AND date='$date'"); 


while ($row = mysql_fetch_array($query)){ 


$name=$row['street']; 
$lat=$row['latitude']; 
$lon=$row['longitude']; 
$desc=$row['district']; 

echo ("addMarker($lat, $lon,'<b>$name</b><br/>$desc')\n"); 

} 

?> 
center = bounds.getCenter(); 
map.fitBounds(bounds); 

} 
</script> 



</head> 
<body onload="initMap()" style="margin:0px; border:0px; padding:0px;"> 


<div id="map"></div> 
</html> 
+1

你知道你在「$郵件」和「$日期」空白?在查詢中使用它們之前,先嚐試檢查$ mail和$ date的值,以此來提高安全性;-) – Stefan

+0

'mysql'調用已被正式棄用,請切換到'mysqli'或'pdo' –

+0

您有空白您的查詢參數。刪除'$ mail'的前導和尾部空格以及尾部空格替換'$ date' –

回答

-1

替換您的查詢與this.Hope它的工作原理。

$query = mysql_query("SELECT * FROM trackEmployee WHERE employeeEmail='".$mail."'AND date='".$date."'"); 
+1

這會造成什麼區別? –

+1

據我可以看到@ Fred-ii-,none。 –

+0

*完全是Sam * - @JayBlanchard –

相關問題