TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-04-2008, 11:02 PM   #1 (permalink)
The Visitor
 
worldop's Avatar
 
Join Date: Dec 2008
Location: UK
Posts: 2
Thanks: 1
worldop is on a distinguished road
Default 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
worldop is offline  
Reply With Quote
Old 12-04-2008, 11:15 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Would this not require Ajax to change the second dropdown depending on the content of the first? So for instance, if the user selects "Bristol" from the first dropdown, should an Ajax call be made to acquire the destinations available for the chosen departure?

Take a look at Teletext Holidays and how they did it. You will notice that when you select a location to depart from, the destination list will update, displaying only those available for the previously selected departure.

The aforementioned is achieved by an Ajax call to this page, with the following POST parameters:

Code:
{"knownCategoryValues":"SearchFrom:-9;","category":"SearchGateway","stype":"Package_Holidays","departuredate":"11/12/2008"}
The response we are given is a JSON formatted response, which is then used to populate the second dropdown on-the-fly based on the first. I believe this is what you're after.

Incidentally, welcome to the community, you little devil! I hope you enjoy your stay here.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
worldop (12-04-2008)
Old 12-04-2008, 11:29 PM   #3 (permalink)
The Visitor
 
worldop's Avatar
 
Join Date: Dec 2008
Location: UK
Posts: 2
Thanks: 1
worldop is on a distinguished road
Default

Its exactly what I'm after :) didn't know I had to use Ajax though *tutorials here i come*
Thanks, i'll update when im done
__________________
If something bad is going to happen, it will.
worldop is offline  
Reply With Quote
Old 12-04-2008, 11:51 PM   #4 (permalink)
The Acquainted
 
KingOfTheSouth's Avatar
 
Join Date: Oct 2008
Location: Cincinnati
Posts: 151
Thanks: 14
KingOfTheSouth is on a distinguished road
Default

I did not have a chance to answer it:( I would have gotten that one too
KingOfTheSouth is offline  
Reply With Quote
Old 12-05-2008, 12:45 AM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

You should possibly try Prototype with this. It will make everything so much easier for you! They also have a fantastic documentation.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem getting data on the html table.... jetnet1 General 2 11-24-2008 06:55 PM
Loading data form table to table? code_junkie Absolute Beginners 5 11-06-2008 03:34 PM
Creating a table from loaded data benton General 5 04-20-2008 11:48 AM
Tips: PHP security Village Idiot Tips & Tricks 22 11-23-2007 11:17 PM


All times are GMT. The time now is 09:46 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design