现在几乎可以工作了。我可以在表格中得到结果,但由于某种原因,它们并不完全正确。
我搜索坐标 x 100 & y 100
我得到的结果只有 x 1-25 & y 1-25 而不是 x 74-125 & y 74-125
<?php
$x = $_POST['x'];
$y = $_POST['y'];
mysql_connect ("localhost","user","pass") or die (mysql_error());
mysql_select_db ("db");
$res = mysql_query("select * FROM table WHERE (x between $x-25 AND $x+25) AND (y BETWEEN $y-25 AND $y+25)");
echo "<table border='1' align='center' cellpadding='5'>";
echo "<tr> <th>City Name</th> <th>X</th> <th>Y</th> </tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $res )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['cityname'] . '</td>';
echo '<td>' . $row['x'] . '</td>';
echo '<td>' . $row['y'] . '</td>';
echo "</tr>";
}
// close table>
echo "</table>";
?>