- Use drop-down menus to pin-point the make, year, and type of cars.
- Output the matching data into a list of links that corresponds to a page like THIS
- Once the user clicks that link, she is brough to a site like above, but with dynamically generated stuff.
The problem I'm basically having is at step 1-2: it's proving difficult to actually a; create the menus and b; get it to output to a list of links. Basically, a search results page.
Here's what the drop-down stuff looks like so far.
<?PHP
$hostName = "*****";
$sqlusername = "*******";
$sqlpassword = "*******";
$databaseName = "[**********]";
$conn = mssql_connect($hostName, $sqlusername, $sqlpassword);
mssql_select_db( $databaseName, $conn);
//show the drop down box from values from the database
echo '<div>
<form method="get" action="">
<select name="make" style="background-color: #0099FF; color:#FFFFFF;">
<option value="NULL">Select Make</option>';
$query = "SELECT carid, MAKE FROM dbo.CARS ORDER BY MAKE";
$result = mssql_query($query);
while($row = mssql_fetch_array($result))
{
echo "<option value=\"{$row[0]}\">{$row[1]}</option>\n";
}
echo '</select><input type="submit" name="submit" value="Get Model!"> ';
if(isset($_GET['MAKE']))
{
$make = (int) $_GET['MAKE'];
}
else{ $make = 0;}
if($make > 0)
echo '
<select name="model">
<option value="NULL">Select Model</option>';
$query1 = "SELECT carid, MODEL FROM dbo.CARS WHERE MAKE = $MAKE";
$result1 = mssql_query($query1);
while($row1 = mssql_fetch_array($result1))
{
echo "<option value=\"{$row1[0]}\">{$row1[1]}</option>\n";
}
echo '</select><input type="submit" name="submit" value="Get Details!">
</form>
</div>';
if(isset($_GET['MODEL']))
{
$model = (int) $_GET['MODEL'];
}
else{ $model = 0;}
if($model > 0)
{
// display the details from the SQL query using the second forms select name
//in the WHERE clause
$query = "SELECT MAKE, MODEL, YEAR
WHERE make.cars = model.cars
AND Model = $model";
$result = mssql_query($query);
echo '<table align="center" cellspacing="2" cellpadding="5" border="1">
<tr>
<td align="left"><b>Make</b></td>
<td align="left"><b>Model</b></td>
<td align="left"><b>Registration</td>
<td align="left"><b>Seats</b></td>
</tr>';
$bg = '#00FF00';
while($row = mssql_fetch_array($result, MSSQL_NUM))
{
$bg =($bg =='#00ff00' ? '#5F6565' : '#00FF00');
echo '<tr bgcolor="' . $bg . '">
<td align="left">' . $row['0'] . '</td>
<td align="left">' . $row['1'] . '</td>
<td align="left">' . $row['2'] . '</td>
<td align="left">' . $row['3'] . '</td>
</tr>';
}
echo '</table>';
}
?>
</body>
</html>
Any help, suggestions at all would be fantastic!
Thanks guys.

New Topic/Question
Reply




MultiQuote


|