我已經保存爲example3.php下面的腳本(從一個大的腳本拍攝):傳遞JavaScript變量到PHP,使MySQL查詢
<script type="text/javascript">
var layer;
//where layer is a table like
------------------------------------
BUSNAME + Category +
------------------------------------
200 Bay + Restaurant +
201 Bay + Bank +
202 Bay + School +
203 Bay + Restaurant +
204 Bay + School +
205 Bay + Restaurant +
206 Bay + Restaurant +
207 Bay + School +
208 Bay + Restaurant +
209 Bay + Restaurant +
------------------------------------
window.location.href = "example3.php?layer="+ layer;
<?php
//Make a MySQL Connection
$query = "SELECT Category, COUNT(BUSNAME)
FROM ".$_GET['layer']." GROUP BY Category";
$result = mysql_query($query) or die(mysql_error());
//Print out result
while($row = mysql_fetch_array($result)){
echo "There are ".$row['COUNT(BUSNAME)']. " " .$row['Category']. "items.";
echo "<br/>";
}
?>
</script>
不要沒有,爲什麼它不工作。任何建議,必須感激。
[SQL注入警報!](http://unixwiz.net/techtips/sql-injection.html) – BalusC 2011-04-27 21:30:49
爲圖層變量分配一個值.. – 2011-04-27 21:37:24
@teresko和David,來吧,不要點它告訴那個人如何解決它! – Johan 2011-04-27 21:53:54