Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. <?PHP
  2. echo "<body bgcolor=#FFFFCC>";
  3. $choix = $_GET['choix'] ;
  4. echo '<div style="color: blue; font-family: arial; font-size: 10px;">';
  5. $requette = formulaire($choix);
  6. $reponse = connexion($requette);
  7. tab_out($reponse);
  8. echo'</div>';
  9.  
  10. function formulaire($NumReq) {
  11. switch($NumReq)
  12. {
  13. case 1:
  14. $req = 'SELECT PLNUM,PLNOM FROM PILOTE';
  15. break;
  16. case 2:
  17. $req = 'SELECT DISTINCT * FROM PILOTE WHERE (SALAIRE >= 18000)';
  18. break;
  19. case 3:
  20. $req = "SELECT DISTINCT * FROM VOL WHERE HEUREDEP BETWEEN '09:00:00' AND '13:00:00'";
  21. break;
  22. }
  23. return $req;
  24. }
  25.  
  26. function connexion($req) {
  27. $host ="localhost:3306";
  28. $user ="root";
  29. $password ="";
  30. $dbname ="Transport_aerien";
  31. $connect = @mysql_connect($host, $user, $password); // @ n'affiche pas les erreurs de la fonction
  32. if (!$connect) { die('Impossible de se connecter : ' . mysql_error()); } else echo 'Connexion reussie<br/>';
  33. $db_selected = mysql_select_db($dbname, $connect);
  34. if (!$db_selected) { die ('Impossible de selectionner la bd : ' . mysql_error()); } else echo 'selection BD reussie<br/>';
  35. echo "Requete : $req<br>";
  36. $reponse = mysql_query($req);
  37. mysql_close($connect);
  38. return $reponse;
  39. }
  40.  
  41. function tab_out($result) {
  42. $N = mysql_num_fields($result); // N = nombre de colonnes du tableau $result
  43. printf("<table border='0' cellpadding='1' cellspacing='1' style='font-family: arial; font-size: 10px;'>");
  44. printf("<tr style='color: black;' bgcolor=#D0D0D0>");
  45. for ($i=0; $i<$N; $i++) printf("<th>%s</th>", mysql_field_name($result,$i));
  46. echo "</tr>";
  47. while ( $ligne = mysql_fetch_array( $result, MYSQL_NUM ))
  48. { echo "<tr style='color: maroon;' bgcolor='#E8E8E8'>";
  49. for($n=0; $n<$N ; $n++) printf("<td>%s</td>", $ligne[$n]);
  50. echo "</tr>";
  51. }
  52. echo "</table>";
  53. }
  54.  
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement