Results 1 to 3 of 3

Thread: select dropdown with two Sql query

  1. #1
    Join Date
    Jun 2011
    Posts
    2

    question select dropdown with two Sql query

    Hi,

    I have some difficulty with my 'select'

    In my select/menu, I display all the options come from a table (table_db_email) in my database

    In this table (tb_code_prmtn11_email) I have two field :
    fld_email_id
    fld_name_email

    It works here is a code
    PHP Code:
    <select name="email_adress_menu" id="email_adress_menu"  class="valid"  onchange="submit()">
            <?php
                
                
    echo "<option selected=\"selected\" value=''>Choose your name</option>"
               

                
    $req_email_adress_menu =   " select DISTINCT id_email, fld_name_email, fld_adresse_email FROM $table_db_email ORDER BY fld_name_email ";
                          
                
    $rep_email_adress_menu =  mysql_query($req_email_adress_menu$cnx) or die( mysql_error() ) ;
                
                
                
                while(
    $show_email_adress_menu mysql_fetch_assoc($rep_email_adress_menu)) {
                   
                    
                    echo 
    '<option value="'.$show_email_adress_menu['id_email'].'"';
                                        
    //if($primes==$show_email_adress_menu['fld_name_email']){echo " selected";} //display to select an option!!!!!!!!!!!!!!!!
                                        
    echo '>'.$show_email_adress_menu['fld_name_email'].'  - '.$show_email_adress_menu['fld_adresse_email'].'</option>';
                                        
                                        
                                
                    

                }
            
    ?>
          </select>
    I have some other information come from another table : tb_code_prmtn11 (containing information about people)
    I have a few fields :
    id_resultat
    fld_name
    fld_email_id
    ( FOREIGN KEY (`fld_email_id`) REFERENCES `tb_code_prmtn11_email` (`id_email`) ON DELETE NO ACTION ON UPDATE CASCADE
    ...

    I want to put this menu on another Web page and this select must display all of the options as below( with) BY SELECTING THE OPTION THAT MATCHES THE INFORMATION FOUND IN THE SECOND TABLE : tb_code_prmtn11

    How can I do this ?

    I know how I can make to my request :

    here is a code MySql :
    Code:
    SELECT td.id_resultat,td.fld_email_id,email.fld_name_email
    FROM $table_db td 
    									   
    INNER JOIN $table_db_email email
    ON td.fld_email_id = email.id_email 
    			
    WHERE td.id_resultat=$id
    This code works also but I don't know how I can include this second query in my menu... Can you help me please

  2. #2
    Join Date
    Jan 2006
    Posts
    605

    Re: select dropdown with two Sql query

    Can you try to add some line of code in dropdownlist's selected index changed to get the job done as following.

    PHP Code:
    protected void DropDownList1_SelectedIndexChanged(object senderEventArgs e
        { 
            
    SqlDataSource1.InsertCommandType SqlDataSourceCommandType.Text
            
    SqlDataSource1.InsertCommand "Insert into [trails] (Location) values('" DropDownList1.SelectedValue "')"
            
    SqlDataSource1.Insert(); 
        } 
     
    please add the folloing line at dropdownlist's tag in aspx page 
     
    OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1" 

  3. #3
    Join Date
    Jun 2011
    Posts
    2

    question Re: select dropdown with two Sql query

    Hi Janos,

    Thanks for your help...


    I made some mistake... Now, my menu works : It display all of the option : with this following code :

    PHP Code:
    <select name="email_menu" id="email_menu" onchange="submit()">
            <?php
                
                
    echo "<option selected=\"selected\" value=''>Choose your name</option>"
               

                
    $req_email_menu =   " select DISTINCT id_email, fld_nom_email, fld_adresse_email FROM $table_db_email ORDER BY fld_nom_email ";
                          
                
    $rep_email_menu =  mysql_query($req_email_menu$cnx) or die( mysql_error() ) ;
                
                
                
                while(
    $show_contenu_email_menu mysql_fetch_assoc($rep_email_menu)) {
                   
                    
                    echo 
    '<option value="'.$show_contenu_email_menu['id_email'].'"';
                    
                    
                    

                            
                            
    //if($primes==$show_contenu_email_menu['fld_nom_email']){echo " selected";} // pour afficher la selectionne
                                        
    echo '>'.$show_contenu_email_menu['fld_nom_email'].'  - '.$show_contenu_email_menu['fld_adresse_email'].'</option>';
                                        
                                        
                                
                    

                }
            
    ?>
          </select>
    I get the following code in FireFox :
    Code:
    <select name="email_menu" id="email_menu" onchange="submit()">
    
            <option selected="selected" value=''>Choose your name</option><option value="tomo">TOTO MONO  - toto.mono@test.com</option><option value="kito">KIKI TOTO - kiki.toto@test.com</option></select>
    Now I want display option selected with other option

    Here is my new code :
    PHP Code:
    <select name="email_menu" id="email_menu" onchange="submit()">
            <?php
                
                
    echo "<option selected=\"selected\" value=''>Choose your name</option>"
               

                
    $req_email_menu =   " select DISTINCT id_email, fld_nom_email, fld_adresse_email FROM $table_db_email ORDER BY fld_nom_email ";
                          
                
    $rep_email_menu =  mysql_query($req_email_menu$cnx) or die( mysql_error() ) ;
                
                
                
                while(
    $show_contenu_email_menu mysql_fetch_assoc($rep_email_menu)) {
                   
                    
                    echo 
    '<option value="'.$show_contenu_email_menu['id_email'].'"';
                    
                    
                    
    ////////***************************************** to display/show item selected
                    
                    
    $req_email_adress_menu_for_selected =   "SELECT td.id_resultat,td.fld_email_id,email.fld_nom_email
                                           FROM 
    $table_db td 
                                           
                                           INNER JOIN 
    $table_db_email email
                                           ON td.fld_email_id = email.id_email 
                
                                           WHERE td.id_resultat=
    $id ";
                   
    $rep_email_adress_menu_for_selected =  mysql_query($req_email_adress_menu_for_selected$cnx) or die( mysql_error() ) ;
                       while(
    $show_email_adress_menu_for_selected mysql_fetch_assoc($rep_email_adress_menu_for_selected)) 
                       {
                        if(
    $emailselected==$show_email_adress_menu['fld_email_id']){echo " selected";} //display to select an option!!!!!!!!!!!!!!!!
                        
    }
                    
    /////--------------------------------
                            //if($primes==$show_contenu_email_menu['fld_nom_email']){echo " selected";} // pour afficher la selectionne
                                        
    echo '>'.$show_contenu_email_menu['fld_nom_email'].'  - '.$show_contenu_email_menu['fld_adresse_email'].'</option>';
                                        
                                        
                                
                    

                }
            
    ?>
          </select>
    My menu works but all options are selected, however, in reality, there is an option that is selected because in my database, there is one in each but all options are selected, however, in reality, there is an option that is selected because in my database, there is one in each recording

    I get the following code in FireFox

    Code:
    <select name="email_menu" id="email_menu" onchange="submit()">
    
            <option selected="selected" value=''>Choose your name</option><option value="tomo"  selected>TOTO MONO  - toto.mono@test.com</option><option value="kito"  selected>KIKI TOTO - kiki.toto@test.com</option></select>

Similar Threads

  1. Want to make query dependent on another query.
    By MACE in forum Software Development
    Replies: 4
    Last Post: 01-02-2010, 05:22 PM
  2. MySQL query select all columns but exclude specific.
    By RSeven in forum Software Development
    Replies: 3
    Last Post: 29-07-2009, 09:26 PM
  3. Turn on MySQL query cache to speed up query performance
    By DMA2Superman in forum Software Development
    Replies: 3
    Last Post: 07-07-2009, 10:26 AM
  4. datediff query mssql select
    By John mitchell in forum Software Development
    Replies: 3
    Last Post: 09-06-2009, 10:43 PM
  5. SELECT UNIQUE and SELECT DISTINCT
    By TAARIQ in forum Software Development
    Replies: 3
    Last Post: 03-06-2009, 10:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,121,970.32881 seconds with 17 queries