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
| <?php
// connexion a la BD
// Paramètres persos
$host = "localhost"; // voir hébergeur
$user = "root"; // identifiant de votre BD (vide ou "root" en local)
$pass = ""; // mot de passe de votre BD (vide en local)
$bdd = "test1"; // nom de la BD
// --------------------------------
// connexion
@mysql_connect($host,$user,$pass) or die("Impossible de se connecter");
@mysql_select_db("$bdd") or die("Impossible de se connecter");
// --------------------------------
?>
<html>
<head>
<title>Test de récuparation de données</title>
</head>
<body>
<?php
// lancement de la requete
$sql = 'SELECT * FROM test_table2 WHERE expediteur = "expe1"';
// on lance la requête (mysql_query) et on impose un message d'erreur si la requête ne se passe pas bien (or die)
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
// on recupere le resultat sous forme d'un tableau
$data = mysql_fetch_array($req);
// on libère l'espace mémoire alloué pour cette interrogation de la base
mysql_free_result ($req);
mysql_close ();
?>
<p>Les informations correspondantes à l identifiant 65 sont :</p><br />
<table>
<thead>
<tr> <th> Expediteur </th>
<th> Libelle </th>
<th> Date de Réception<br /> dans nos locaux </th>
<th> Delais estimé pour <br />avoir les resultats </th>
<th> Statut </th>
</tr>
</thead>
<tbody>
<?php
$i = 1; $count = count($data);
while($i <= $count){
echo "<tr>"; echo "<td>";
echo $data[$i][4];
echo "</td>";
echo "<td>";
echo $data[$i][1];
echo "</td>";
echo "<td>";
echo $data[$i][2];
echo "</td>";
echo "<td></td>";
echo "<td> ";
switch ( $data[$i][3] )
{
case '1' : echo "statut1"; break;
case '2' : echo "statut2"; break;
case '3' : echo "statut3"; break;
case '4' : echo "statut4"; break;
case '5' : echo "statut5"; break;
case '6' : echo "statut6"; break;
default : echo "pas marché";
}
echo "</td>";
echo "</tr>";
i++;
} ?>
</tbody>
</table>
</body>
</html> |
Partager