我为公交路线创建了一个搜索功能。我创建了一个索引页面:
<DOCTYPE! html>
<head>
<title>Search</title>
<body>
Enter info below:
<br />
<form action='routes.php' action='get'>
Start Destination:
<select name="start">
<option value="StopA">Stop A</option>
</select>
<br />
End Destination:
<select name="stop">
<option value="StopZ">Stop Z</option>
</select>
Departing between (start):
<select name="start_time">
<option value="13:40">13:40</option>
<option value="13:45">13:45</option>
<option value="13:50">13:50</option>
<option value="13:55">13:55</option>
</select>
<br />
Departing between (end):
<select name="end_time">
<option value="13:40">13:40</option>
<option value="13:45">13:45</option>
<option value="13:50">13:50</option>
<option value="13:55">13:55</option>
</select>
<input type="submit" value="Submit">
</form>
和连接到我的数据库的“路线”页面
<?php
mysql_connect('', '', '');
$start = $_GET['start'];
$stop = $_GET['stop'];
$start_time = $_GET['start_time'];
$end_time = $_GET['end_time'];
$query = mysql_query("SELECT * FROM searchengine.times where STOP_1 = '$start' and STOP_7 = '$stop' and time(time) between '$start_time' and '$end_time'") or die(mysql_error());
echo "<table border='1'>";
echo "<tr> <th>Departure Time</th> <th>Route No.</th> <th>Stop 1</th> <th>Stop 2</th> <th>Stop 3</th> <th>Stop 4</th> <th>Stop 5</th> </tr>";
while($row = mysql_fetch_array($query))
{
echo "<tr><td>";
echo $row['time'];
echo "</td><td>";
echo $row['route_no'];
echo "</td><td>";
echo $row['STOP_1'];
echo "</td><td>";
echo $row['STOP_2'];
echo "</td><td>";
echo $row['STOP_3'];
echo "</td><td>";
echo $row['STOP_4'];
echo "</td><td>";
echo $row['STOP_5'];
echo "</td></tr>";
echo $row['STOP_6'];
echo "</td></tr>";
echo $row['STOP_7'];
echo "</td></tr>";
}
echo "</table>";
?>
当我从我的起始巴士站搜索到终点巴士站时,我没有得到任何结果。
我的数据库看起来像这样:
time(PM) STOP_1 STOP_2 STOP_3 STOP_4 STOP_5 STOP_6 STOP_7 route_no.
13:00
13:20
13:40
14:00
这是对的吗?任何人都可以看到我的代码问题在哪里,或者如果有人对如何改进它有任何建议我会非常感激。
亲切的问候,关键
答案 0 :(得分:0)
我认为问题在于and time(time)
用反引号改变它
由于时间是关键字,因此应使用time(`time`)