Advertisement
Guest User

Untitled

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