Advertisement
Guest User

Untitled

a guest
May 27th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. <html>
  2.  
  3. <body>
  4.  
  5. <?php
  6.  
  7. //Fichier de connection à la base de données
  8.  
  9. $host = "localhost"; // voir hébergeur
  10.  
  11. $user = "root"; // vide ou "root" en local
  12.  
  13. $pass = ""; // vide en local
  14.  
  15. $bdd = "projetsite"; // nom de la BD
  16.  
  17. // connexion
  18.  
  19. $link=@mysql_connect($host,$user,$pass)
  20.  
  21. or die("Impossible de se connecter");
  22.  
  23. @mysql_select_db("$bdd")
  24.  
  25. or die("Impossible de se connecter");
  26.  
  27.  
  28.  
  29. // requête SQL qui compte le nombre total d'enregistrement dans la table et qui
  30.  
  31. //récupère tous les enregistrements
  32.  
  33. $select = 'SELECT id,utilisateur,titre,date,corrige,description,criticite FROM incident';
  34.  
  35. $result = mysql_query($select,$link) or die ('Erreur : '.mysql_error() );
  36.  
  37. $total = mysql_num_rows($result);
  38.  
  39.  
  40.  
  41.  
  42.  
  43. // si on a récupéré un résultat on l'affiche.
  44.  
  45. if($total) {
  46.  
  47. // debut du tableau
  48.  
  49. echo '<table bgcolor="#FFFFFF">'."\n";
  50.  
  51. // première ligne on affiche les titres prénom et surnom dans 2 colonnes
  52.  
  53. echo '<tr>';
  54.  
  55. echo '<td bgcolor="#669999"><b><u>id</u></b></td>';
  56.  
  57. echo '<td bgcolor="#669999"><b><u>titre</u></b></td>';
  58.  
  59. echo '<td bgcolor="#669999"><b><u>corrige</u></b></td>';
  60.  
  61. echo '<td bgcolor="#669999"><b><u>description</u></b></td>';
  62.  
  63. echo '<td bgcolor="#669999"><b><u>criticite</u></b></td>' ;
  64.  
  65. echo '<td bgcolor="#669999"><b><u>utilisateur</u></b></td>';
  66.  
  67. echo '<td bgcolor="#669999"><b><u>date</u></b></td>';
  68.  
  69. echo '</tr>'."\n";
  70.  
  71. // lecture et affichage des résultats sur 2 colonnes, 1 résultat par ligne.
  72.  
  73. while($row = mysql_fetch_array($result)) {
  74.  
  75. echo '<tr>';
  76.  
  77. echo '<td bgcolor="#CCCCCC">'.$row["id"].'</td>';
  78.  
  79. echo '<td bgcolor="#CCCCCC">'.$row["titre"].'</td>';
  80.  
  81. echo '<td bgcolor="#CCCCCC">'.$row["corrige"].'</td>';
  82.  
  83. echo '<td bgcolor="#CCCCCC">'.$row["description"].'</td>';
  84.  
  85. echo '<td bgcolor="#CCCCCC">'.$row["criticite"].'</td>';
  86.  
  87. echo '<td bgcolor="#CCCCCC">'.$row["utilisateur"].'</td>';
  88.  
  89. echo '<td bgcolor="#CCCCCC">'.$row["date"].'</td>';
  90.  
  91. echo '</tr>'."\n";
  92.  
  93. }
  94.  
  95. echo '</table>'."\n";
  96.  
  97. // fin du tableau.
  98.  
  99. }
  100.  
  101. else echo 'Pas d\'enregistrements dans cette table...';
  102.  
  103.  
  104.  
  105. // on libère le résultat
  106.  
  107. mysql_free_result($result);
  108.  
  109. ?>
  110.  
  111. </body>
  112.  
  113. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement