「マイレージ」ダウンリストオプションで問題が発生している動的SQL検索があります。
<?php
include('connection.php');
if(isset($_POST['Make']))
{
$makeSearch = $_POST['Make'];
$modelSearch = $_POST['Model'];
$colourSearch = $_POST['Colour'];
$townSearch = $_POST['Town'];
$regionSearch = $_POST['Region'];
$regiSearch = $_POST['Reg'];
$maxSearch = $_POST['MaxPrice'];
$minSearch = $_POST['MinPrice'];
$maxMilSearch = $_POST['MaxMil'];
}
else
{
$makeSearch = $_GET['Make'];
$modelSearch = $_GET['Model'];
$colourSearch = $_GET['Colour'];
$townSearch = $_GET['Town'];
$regionSearch = $_GET['Region'];
$regiSearch = $_GET['Reg'];
$maxSearch = $_GET['MaxPrice'];
$minSearch = $_GET['MinPrice'];
$maxMilSearch = $_GET['MaxMil'];
}
if(!isset($_GET['pageNo']))
{
$pageNo = 0;
}
else
{
$pageNo = $_GET['pageNo'];
}
$noOfRecords = 4;
$startRecord = $pageNo * $noOfRecords;
$nextPage = $pageNo + 1;
$prevPage = $pageNo - 1;
$curpage = $pageNo + 1;
$sql2 = "SELECT * FROM cars WHERE 1=1";
if($makeSearch !== "Select Make")
{
$sql2 .= " AND make = '$makeSearch'";
}
.....................
if($maxMilSearch !== "Select Max Mileage")
{
$sql2 .= " AND miles <= '$maxMilSearch'";
}
$sql = "SELECT * FROM cars WHERE 1=1";
if($makeSearch !== "Select Make")
{
$sql .= " AND make = '$makeSearch'";
}
.........................
{
$sql .= " AND miles <= '$maxMilSearch'";
}
$sql .= "LIMIT $startRecord, $noOfRecords";
$result2 = mysql_query($sql2,$odbc) or die ("Can't run query1");
$result = mysql_query($sql,$odbc) or die ("Can't run query2");
echo"$sql";
$num_rows = mysql_num_rows($result2);
echo"$num_rows";
$last = ceil($num_rows/$noOfRecords);
if(mysql_num_rows($result) == 0)
{
echo "No cars found";
}
else
{
echo "<table border = 1>";
while($row=mysql_fetch_object($result))
{
echo "<tr>";
echo"<td>";
echo$row->make;
echo"</td>";
echo"<td>";
echo$row->model;
echo"</td>";
echo"<td>";
echo$row->Reg;
echo"</td>";
echo"<td>";
echo$row->colour;
echo"</td>";
echo"<td>";
echo$row->miles;
echo"</td>";
echo"<td>";
echo$row->price;
echo"</td>";
echo"<td>";
echo$row->dealer;
echo"</td>";
echo"<td>";
echo$row->telephone;
echo"</td>";
echo"<td>";
echo$row->description;
echo"</td>";
echo"<td>";
echo$row->carIndex;
echo"</td>";
echo"<td>";
echo$row->region;
echo"</td>";
echo"<td>";
echo$row->town;
echo"</td>";
echo"<td><a href='look.php?carIndex=$row->carIndex&Reg=$row->Reg&make=$row->make&model=$row->model&colour=$row->colour&price=$row->price&miles=$row->miles&dealer=$row->dealer&telephone=$row->telephone&description=$row->description®ion=$row->region'>More Info</a></td>";
echo"</tr>";
}
echo "<tr>";
echo"$curpage";
echo"$last";
if($pageNo >= 1)
{
echo "<td><a href='search.php?pageNo=$prevPage&Make=$makeSearch&Model=$modelSearch&Reg=$regiSearch&MaxMil=$maxMilSearch&Colour=$colourSearch&Town=$townSearch&Region=$regionSearch&MaxPrice=$maxSearch&MinPrice=$minSearch'>Previous</a></td>";
}
if($pageNo < $last - 1)
{
echo "<td><a href='search.php?pageNo=$nextPage&Make=$makeSearch&Model=$modelSearch&Reg=$regiSearch&MaxMil=$maxMilSearch&Colour=$colourSearch&Town=$townSearch&Region=$regionSearch&MaxPrice=$maxSearch&MinPrice=$minSearch'>Next</a></td>";
}
echo"</tr>";
echo"</table>";
}
?>
私が抱えている問題は、「マイレージ」の入力が無視されていることです。たとえば、ドロップダウン リストから 5000 マイルを入力して、これ以下のすべての車を返すと、任意の走行距離でランダムな結果が返されます。たとえば、車のメーカーを選択してから走行距離を選択すると、正しい結果が返されるということです。
他のすべてのオプションが正しく機能するため、ここで何が間違っているのか本当にわかりません。
どんな助けでも素晴らしいでしょう!