Current location: Hot Scripts Forums » Programming Languages » PHP » how to create two dropdown menu linking each other?

how to create two dropdown menu linking each other?

Reply
  #1 (permalink)  
Old
Newbie Coder
 
Join Date: Nov 2010
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
how to create two dropdown menu linking each other?

Hi guys, i have to create a drop-down menu for database data, when i select one data from that then next drop-down menu has to create automatically with related data of the 1st selection.
could anyone please give me some help to do this?

NB: i have 3 tables student(sid, sname), course (cid, cname) , take (sid, cid) so if i select one of the cid then another drop down list has to create automatically with sid who is taking the cid .
Reply With Quote

Featured Marketplace Scripts (view more)

  #2 (permalink)  
Old
Icepick.pt's Avatar
Newbie Coder
 
Join Date: Nov 2010
Location: Setúbal, near Lisbon
Posts: 96
Thanks: 3
Thanked 7 Times in 7 Posts
Sometime ago I've built a little something similar to what you need.
I needed to have a product classification under a family and then under a sub-family.
This is how I got it done. It should refresh the second combobox automatically as you chage the first one.

PHP Code:


$string_pesquisa
="    select       cliente_nr
                            , familia_name
                            , codigo_familia_pk  ( this is the primary key )
                    from stocks_produtos_familias"
;
            
$fam=mysql_query($string_pesquisa,$_SESSION[connection]);
# determines the master combo
$combo_familia="
    <select name='prod_familia' onchange='javascript: document.form.submit();'>
        <option value='0'>&nbsp</option>"
;
while (
$familia=mysql_fetch_row($fam)) {
    
# if this the selected family
    
if ($familia[2]==$_POST[prod_familia])     {
        
$sel="selected='selected'";
        
# sets up the slave combo
        
$string_pesquisa="    select     cliente_nr, 
                                    codigo_familia_master,
                                    sub_familia_name,
                                    sub_familia_pk (this is the sub family primary key)
                            from stocks_produtos_subfamilias
                            and codigo_familia_master=
$_POST[prod_familia]";
        
$sub_fam=mysql_query($string_pesquisa,$_SESSION[connection]);
        if (
mysql_num_rows($sub_fam)>0)    {
            
$combo_subfamilia="Subfamilia<br/>
            <select name='prod_subfamilia' class='preto' style='background:white; padding:3px; border: thin solid grey;' 
                onchange='javascript: document.alt_produto.submit();'>
                <option value='0'>&nbsp</option>"
;
            
# builds up the slave combo
            
while ($sub_familia=mysql_fetch_row($sub_fam)) {
                if (
$sub_familia[3]==$ficha_produto[4])     {$sel_2="selected='selected'";}
                else                                         {
$sel_2=NULL;}
                
$combo_subfamilia.="<option value='$sub_familia[3]$sel_2>$sub_familia[2]</option>";
                }
            
$combo_subfamilia.="</select>";
            }
        }
        
# sif this is not the selected family
    
else {$sel=NULL;}    
    
$combo_familia.="<option value='$familia[2]$sel>$familia[1]</option>";
    }
$combo_familia.="</select>";


echo 
"

<form name='alt_produto' method='post' action='
$_SERVER[PHP_SELF]'>
    
$combo_familia   <br/>
    
$combo_subfamilia

</form>
"

On the same basis you can build a similar to suit you.
Have fun!

Last edited by Icepick.pt; 11-14-10 at 07:14 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Create dropdown menu from comma separated list of numbers maya77 PHP 22 03-20-11 11:35 AM
Superfish jquery menu problems with modification transcend2005 CSS 2 03-25-09 01:30 AM
css problem with the scroll bar crazy.works CSS 0 11-04-08 05:34 PM
Xml / Dom / Css Mark_SC.SE JavaScript 0 06-29-05 08:05 AM


All times are GMT -5. The time now is 04:37 AM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.