1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| <html>
<head>
</head>
<body>
<?php
if(isset($_POST['liste1'])){
//si la liste a été "postée" c ad choix fait
$liste1=$_POST['liste1'];
}else{
$liste1=-1;
}
?>
Sélectionnez une societe :
<form name="form1" method="post" action="affiche.php">
<select name="liste1" onChange="form1.submit();">
<option value="-1">-- Choisissez -- </option> <!-- il faut cette ligne pour avoir obliagtoirement un changement -->
<?php
$connection = mysql_connect('localhost', 'root', '');
$base = mysql_select_db('etudiants_smi');
$requete = "SELECT Nom FROM societe";
$execution_requete = mysql_query($requete);
while($total = mysql_fetch_array($execution_requete))
//Liste déroulante
{
echo "<option value=\"".$total["Nom"]."\"";
if($liste1==$total['Nom']) { echo "selected"; }//ça c'est pour garder la selection lors du réaffichage
echo ">".$total['Nom']."</option>\n";
}
?>
</select>
</form>
<?php
if($liste1 != -1){ //si on a fait un choix
//on refait une requette avec une condition
$requete = "select * from carriere,etat_civil,societe where carriere.cne=etat_civil.CNE and carriere.n_societe=societe.n_societe and societe.Nom='".$liste1."'";
$execution_requete = mysql_query($requete);
// on affiche les valeurs correspondantes au nom selectionné, pas besoin de boucle while, il n'y en aura qu'un
$total = mysql_fetch_array($execution_requete);
echo "les laureats de societe est :</br>";
echo "Nom: ".$total['Nom']."<br />Prenom: ".$total['prenom']."<br />Tel: ".$total['tel']."<br />Email: ".$total['email'];
}
//fermeture connexion à mysql
mysql_close();
?>
</body>
</html> |
Partager