12-04-2008, 11:02 PM
|
#1 (permalink)
|
|
The Visitor
Join Date: Dec 2008
Location: UK
Posts: 2
Thanks: 1
|
drop downs from table data
Hello, I'm developing a booking system. I've got a database, with records such as( colon representing column break ):
Bristol : Newcastle
Bristol : Manchester
Manchester : Bristol
and so on, I'm trying to make drop down menu's for Departing City, and Destination City using <select><option> html. I'm getting duplicate drop-down options and im not sure how to display one of each of the departing/destination records, Also another thing I don't know how to do is, only display the corresponding Destination: e.g.
if the Departing City is Bristol, then only the destinations from Bristol should appear in the second drop-down.
Here is my code so far, if anyone could help it would be appreciated, thanks.
php Code:
$Query = "SELECT DISTINCT DepartingFrom FROM flights"; $RunQuery = mysqli_query ($dbc, $Query) or trigger_error("Query: $Query\n<br />MySQL Error: " . mysqli_error ($dbc)); if(mysqli_num_rows ($RunQuery) > 0){ echo '<h1>Book your flight here</h1><br /> <b>Airport to fly from:</b>'; echo '<select>'; while($Row = mysqli_fetch_array ($RunQuery)){ echo '<option>' . $Row[ 'DepartingFrom'] . '</option>'; } /* end of while loop */ echo '</select><br />'; echo '<b>Airport to Fly to:</b> <select>'; $Query = "SELECT ArrivalAt FROM flights"; $RunQuery = mysqli_query ($dbc, $Query) or trigger_error("Query: $Query\n<br />MySQL Error: " . mysqli_error ($dbc)); while($Row = mysqli_fetch_array ($RunQuery)){ echo'<option>' . $Row[ 'ArrivalAt'] . '</option>'; } /* end of while loop */ echo'</select>'; echo '<br />'; } /* end of if statement - add error if there were no rows in flights */
__________________
If something bad is going to happen, it will.
Last edited by worldop : 12-04-2008 at 11:16 PM.
Reason: Solved the first bit of the problem by using the "DISTINCT" keyword for SQL
|
|
|
|