double combobox

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vamsi_j
Forum Newbie
Posts: 5
Joined: Tue Jan 02, 2007 6:49 am

double combobox

Post by vamsi_j »

Hi i need a double combobox which needs the data to be fetched from the database dynamically.


database details there are two fields in the database name and email address

name email

Vamsi vamsi@vamsi.com

Vamsi krishna@vamsi.com

Krishna xyz@xyz.com

Krishna xyz@xyz.com

i need to fill the first combobox only with the names Vamsi and Krishna

If i select the name as Vamsi i need to get the two email address corresponding to Vamsi.

I was successful in populating one combobox.I failed in selections. Any sort of code help is appreciated.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Firstly, I'd grab the names and e-mails from the database and store them in an array.
Secondly, generate the combo box in a loop that loops through as many times as there are items in the array using:

Code: Select all

value = '$yourArray[$i]'
for the values of each combo option.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you're looking for "chained select".
There are a lot of hits on google for that search term.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

On this site I have created a couple of topics on this...
Javascript and Dynamic Select Boxes
Dynamic/Chained Selects using Ajax with Prototype

At some point soon I will probably do another example using the JQuery javascript library.
desb01
Forum Newbie
Posts: 5
Joined: Tue May 01, 2007 9:39 pm

PHP only

Post by desb01 »

Is it possible to do it without using javascript (using only php).

I created two combobox filling with php and mySql.

But I need the second combobox to show choice based on the selection of the first combobox.

How do I do that ?

Thank you in advance.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

If you do not have javascript (or don't want to use it) your only alternative is to submit the form when the user selects the first item. This is normally performed with a submit button next to the first select item.
Dynamic/Chained Selects using Ajax with Prototype has an example which works even with javascript switched off.
Post Reply