dropdown with two Sql query
| From: | asp kiddy | Date: | Sat, 25 Jun 2011 20:57:46 +0000 |
| Subject: | dropdown with two Sql query | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-313719@lists.php.net to get a copy of this message | ||
Hi,
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 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>
<-----end----code--------------------
I have some other information coming 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 ?
------------code-------------------->
SELECT td.id_resultat,td.fld_email_id,email.fld_name_email
FROM $table_db td
JOIN $table_db_email email ON td.fld_email_id = email.id_email
WHERE td.id_resultat = $id
<-----end----code--------------------
This code works also but I don't know how I can include this second query in my menu...
Do you have an idea for me ?