我想回显我想要的结果,如何进一步过滤它们?
例如, search x100 y100
, 目前得到数百个结果。我需要进一步过滤这些结果,所以我只得到那些被标记为敌对、待定或友好的结果
我有以下html表单
<form action="xysearch.php" method="post">
<label>X Coord
<input type="text" name="x" />
</label>
<label>Y Coord
<input type="text" name="y" />
</label>
<select name="term">
<option value="Hostile">Hostile</option>
<option value="Pending">Pending</option>
<option value="Friendly">Friendly</option>
</select>
<input type="submit" value="Search" />
</form>
我需要添加到搜索查询中的是一种过滤这些结果的方法,因此只显示在外交下拉列表中选择的选项
到目前为止,我的查询不起作用-我可以获得所有结果,而不仅仅是过滤的结果。
<?php
$x = $_POST['x'];
$y = $_POST['y'];
$term = $_POST['term'];
mysql_connect ("localhost","host","pass") or die (mysql_error());
mysql_select_db ("d_base");
$res = mysql_query("SELECT * FROM my_table WHERE (x BETWEEN $x -75 AND $x +75) AND (y BETWEEN $y -75 AND $y +75) ");
$res2 = mysql_query("SELECT dip FROM my_table WHERE dip IN '%$term%' ORDER BY '%$term%' DESC ");
echo "<table border='1' align='center' cellpadding='5'>";
echo "<tr> <th>City Name</th> <th>X</th> <th>Y</th> <th>Diplomacy</th> </tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $res, $res2 )) {
// echo out the contents of each row into a table
echo '<td>' . $row['city'] . '</td>';
echo '<td>' . $row['x'] . '</td>';
echo '<td>' . $row['y'] . '</td>';
echo '<td>' . $row['dip'] . '</td>';
echo "</tr>";
// close table>
echo "</table>";
}
?>
我不太确定我哪里出错了,因为我实际上可以得到结果来回显,只是过滤就是问题所在。