A 2-part problem using PHP

First using drop-downs to locate data, and then a page to display it

Page 1 of 1

0 Replies - 835 Views - Last Post: 29 April 2008 - 11:03 AM Rate Topic: -----

#1 PSUgammon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 08-October 07

A 2-part problem using PHP

Post icon  Posted 29 April 2008 - 11:03 AM

Hey everyone! I'm working on a project, and we've definitely hit a rough spot. We're to create a database that involves entities of cars and their makes/models, etc. What I'd like to accomplish is this:
  • 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.

$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!"> ';

	$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!">


	$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
  WHERE make.cars = model.cars
  AND Model = $model";
	$result = mssql_query($query);		   
	echo '<table align="center" cellspacing="2" cellpadding="5" border="1">
			<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>
		$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>
	echo '</table>';

Any help, suggestions at all would be fantastic!

Thanks guys.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1