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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
| <?php
/*<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">*/
//header("pragma:no-cache");
// connexion au serveur MySQL
$base_id = mysql_connect("localhost", "script_php", "zh6tjPp6T56N4dbF")
or exit("<p>Impossible de se connecter au serveur MySQL : ".mysql_error()."</p>\n");
// sélection de la base
$selection = mysql_select_db("exercices_php", $base_id)
or exit("<p>Impossible de sélectionner la base : ".mysql_error()."</p>\n");
$formation="select * from formation";
$pays="select * from pays";
//execution de la requete:on envoie la requete au serveur qui nous retourne le resultat
$formation = mysql_query($formation)
or exit("<p>La requête au serveur MySQL a échoué : ".mysql_error()."</p>\n");
$pays = mysql_query($pays)
or exit("<p>La requête au serveur MySQL a échoué : ".mysql_error()."</p>\n");
$ligneformation=mysql_fetch_object($formation);
$lignepays=mysql_fetch_object($pays);
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<title>Recherche d'étudiants</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15" />
</head>
<body>
<h2>Recherche d'étudiants</h2>
<form method="post" action="">
<p>
<label>Nom d'étudiant </label>
<?php
// si un nom a été saisi (lors de la recherche précédente),
// on remplit le champ avec ce nom (conservation de la saisie texte)
echo '<input type="text" name="nom" value="'
.(isset($_POST['nom']) ? htmlspecialchars($_POST['nom']) : '').'" />';
echo "\n";
?>
<br>
Formation : <select name="formation">
<option value="général" selected>Indifférent</option>
<option value="Master M1" <?php if ("$ligneformation->nom"=="Master M1") echo "selected";?>>Master M1</option>
<option value="Master M2" <?php if ("$ligneformation->nom"=="Master M2") echo "selected";?>>Master M2</option>
<option value="DU CPM" <?php if ("$ligneformation->nom"=="DU CPM") echo "selected";?>>DU CPM</option>
<option value="DU TBM" <?php if ("$ligneformation->nom"=="DU TBM") echo "selected";?>>DU TBM</option>
</select><br>
Pays : <select name="pays">
<option value="général" selected>Indifférent</option>
<option value="France" <?php if ("$lignepays->nom"=="France") echo "selected";?>>France</option>
<option value="Maroc" <?php if ("$lignepays->nom"=="Maroc") echo "selected";?>>Maroc</option>
<option value="Burkina Faso" <?php if ("$lignepays->nom"=="Burkina Faso") echo "selected";?>>Burkina Faso</option>
<option value="Irlande" <?php if ("$lignepays->nom"=="Irlande") echo "selected";?>>Irlande</option>
<option value="Sénégal" <?php if ("$lignepays->nom"=="Sénégal") echo "selected";?>>Sénégal</option>
</select><br>
Naissance entre l'année : <select name="année1">
<option value="général" selected> Indifférent</option>
<option value="1989" <?php echo "selected";?>>1989</option>
<option value="1988" <?php echo "selected";?>>1988</option>
<option value="1987" <?php echo "selected";?>>1987</option>
<option value="1986" <?php echo "selected";?>>1986</option>
<option value="1985" <?php echo "selected";?>>1985</option>
<option value="1984" <?php echo "selected";?>>1984</option>
<option value="1983" <?php echo "selected";?>>1983</option>
<option value="1982" <?php echo "selected";?>>1982</option>
<option value="1981" <?php echo "selected";?>>1981</option>
<option value="1980" <?php echo "selected";?>>1980</option>
<option value="1979" <?php echo "selected";?>>1979</option>
<option value="1978" <?php echo "selected";?>>1978</option>
<option value="1977" <?php echo "selected";?>>1977</option>
<option value="1976" <?php echo "selected";?>>1976</option>
</select>
et l'année : <select name="année2">
<option value="général" selected> Indifférent</option>
<option value="1989" <?php echo "selected";?>>1989</option>
<option value="1988" <?php echo "selected";?>>1988</option>
<option value="1987" <?php echo "selected";?>>1987</option>
<option value="1986" <?php echo "selected";?>>1986</option>
<option value="1985" <?php echo "selected";?>>1985</option>
<option value="1984" <?php echo "selected";?>>1984</option>
<option value="1983" <?php echo "selected";?>>1983</option>
<option value="1982" <?php echo "selected";?>>1982</option>
<option value="1981" <?php echo "selected";?>>1981</option>
<option value="1980" <?php echo "selected";?>>1980</option>
<option value="1979" <?php echo "selected";?>>1979</option>
<option value="1978" <?php echo "selected";?>>1978</option>
<option value="1977" <?php echo "selected";?>>1977</option>
<option value="1976" <?php echo "selected";?>>1976</option>
</select><br>
<input type="submit" name="recherche" value="Rechercher" />
</p>
</form>
<?php
// Si une recherche a été effectuée (bouton "Rechercher" cliqué) :
if (isset($_POST['recherche'])) {
// connexion au serveur MySQL
$base_id = mysql_connect("localhost", "script_php", "zh6tjPp6T56N4dbF")
or exit("<p>Impossible de se connecter au serveur MySQL : ".mysql_error()."</p>\n");
// sélection de la base
$selection = mysql_select_db("exercices_php", $base_id)
or exit("<p>Impossible de sélectionner la base : ".mysql_error()."</p>\n");
// Recherche des étudiants dans la base de données
// début de construction de la requête : par défaut, on sélectionne tous les étudiants
$requete = "SELECT etudiant.nom, etudiant.prenom FROM etudiant ";
$requete2 = "SELECT distinct (etudiant.nom), etudiant.prenom FROM etudiant,formation,pays ";
if ($_POST['formation'] and empty($_POST['nom']) and $_POST['pays'] and $_POST['année1'] and $_POST['année2']) {
$formation=$_POST['formation'];
$pays=$_POST['pays'];
$année1=$_POST['année1'];
$année2=$_POST['année2'];
if ($formation!='Indifférent' and $année1!='Indifférent' and $année2!='Indifférent' and $pays!='Indifférent')
{
$requete2.= "WHERE formation.id_formation = etudiant.id_formation AND pays.id_pays=etudiant.id_pays AND extract(year FROM etudiant.date_naissance) BETWEEN '$année1' and '$année2' AND pays.nom= '$pays' AND formation.nom = '$formation'";
}
else
if ($formation='Indifférent' and $année1!='Indifférent' and $année2!='Indifférent' and $pays!='Indifférent')
{
$requete2.= "WHERE pays.id_pays=etudiant.id_pays AND extract(year FROM etudiant.date_naissance) BETWEEN '$année1' and '$année2' AND pays.nom= '$pays'";
}
else
if ( $formation='Indifférent' and $pays='Indifférent' and $année1!='Indifférent' and $année2!='Indifférent')
{
$requete2.= "WHERE extract(year FROM etudiant.date_naissance) BETWEEN '$année1' and '$année2'";
}
else
if ($formation='Indifférent' and $pays='Indifférent' and $année1='Indifférent' and $année2!='Indifférent')
{
$requete2.= "WHERE extract(year FROM etudiant.date_naissance)='$année2'";
}
else
if ($formation='Indifférent' and $pays='Indifférent' and $année1!='Indifférent' and $année2='Indifférent')
{
$requete2.= "WHERE extract(year FROM etudiant.date_naissance)='$année1'";
}
else
if ($formation!='Indifférent' and $pays!='Indifférent' and $année1='Indifférent' and $année2='Indifférent') {
$requete2.= "WHERE formation.id_formation = etudiant.id_formation AND pays.id_pays=etudiant.id_pays AND pays.nom= '$pays' AND formation.nom = '$formation'";
}
else
if ($formation!='Indifférent' and $pays!='Indifférent' and $année1='Indifférent' and $année2='Indifférent')
{
$requete2.= "WHERE formation.id_formation = etudiant.id_formation AND pays.id_pays=etudiant.id_pays AND pays.nom='$pays' AND formation.nom = '$formation'";
}
else
if ($formation='Indifférent' and $pays!='Indifférent' and $année1='Indifférent' and $année2='Indifférent')
{
$requete2.= "WHERE formation.id_formation = etudiant.id_formation AND pays.id_pays=etudiant.id_pays AND pays.nom= '$pays'";
}
else
if ($formation!='Indifférent' and $pays='Indifférent' and $année1='Indifférent' and $année2='Indifférent')
{
$requete2.= "WHERE formation.id_formation = etudiant.id_formation AND pays.id_pays=etudiant.id_pays AND formation.nom = '$formation'";
}
}
//}
//}
//}
// fin de construction de la requête : classement des résultats
// par ordre alphabétique des noms, puis des prénoms
$requete2 .= "ORDER BY etudiant.nom,etudiant.prenom ;";
// exécution de la requête sur la base de données
$etudiants2 = mysql_query($requete2)
or exit("<p>La requête au serveur MySQL a échoué : ".mysql_error()."</p>\n");
// Affichage des étudiants trouvés
echo "<h2>Résultat2</h2>\n";
$etudiant3 = mysql_fetch_array($etudiants2);
if (!$etudiant3)
echo "<p>Aucun étudiant ne correspond à votre recherche.</p>\n";
// autre cas : il y a au moins un étudiant à afficher
else
// écriture d'un paragraphe par étudiant trouvé
do
echo "<p>".htmlspecialchars(strtoupper($etudiant3['nom']))." "
.htmlspecialchars(strtoupper($etudiant3['prenom']))." </p>\n";
/*?>
<a href="recherche_etudiants.php?<?php echo "<p>".htmlspecialchars(strtoupper($etudiant3['nom']))." "
.htmlspecialchars(strtoupper($etudiant3['prenom']))." </p>\n";?>"></a><br>
<? */
while ($etudiant3 = mysql_fetch_array($etudiants2));
} |
Partager