高分找高手解答一道关于网页数据库PHP的题目

来源:百度知道 编辑:UC知道 时间:2024/05/15 20:02:13
首先,用PHP语言连接到数据库,在网页上有2个输入框,分别输入x值和y值,按确认后要求返回所在的code,并显示在网页上。如果不存在该code 就显示empty.
例如我输入 x=12,y=27,那么网页上应该显示 CODE= EDT 1/2,因为 bottomright(15)>x>bottomleft(10), TopLeft(35)>y>TopRight(30).
我得数据库如下,已经建好了:
Code Township Parish Bottomleft Bottomright Topleft Topright
EDT1/2 Acton Acton 10 15 30 35
EDT 2/2 Acton GrangeR 30 45 50 65

<html>
<head>
<title>test</title>
</head>
<body>
<form action="s.php" method="post">
<input type="text" name="x"/>
<input type="text" name="y"/>
<input type="submit" value="提交"/>
</form>
</html>

s.php

<?php
$x = $_POST['x'];
$y = $_POST['y'];
$db = new mysqli('localhost','root','123456','databasename');
$sql = "select Code from tablename where Bottomleft<".$x." and ".$x."<Bottomright and Topleft<".$y." and ".$y."<Topright";
$result = $db->query($sql);
while(false!==($row=$result->fetch_assoc()))
{
echo $row['Code'];
}
?>