Page 1 of 1

select dropdown with two Sql query

Posted: Thu Jun 23, 2011 9:18 am
by aspkiddy
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

Code: Select all

<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 all

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 :crazy:

Re: select dropdown with two Sql query

Posted: Mon Jun 27, 2011 12:43 pm
by Jade
So you're trying to populate a second drop down field depending on the value they've selected in the first drop down field? You can do that with AJAX http://roshanbh.com.np/2008/01/populate ... d-php.html