Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. <body>
  2. <?php
  3. echo "<table style='border: solid 1px black; border-collapse: collapse;
  4. th, td {
  5. padding: 5px;
  6. text-align: left;
  7. }'>";
  8. echo "<tr>
  9. <th>date/th>
  10. <th>Etat de TX1</th>
  11. <th>Etat de TX2</th>
  12. <th>Sur antenne</th>
  13. <th>ALARME</th> </tr>";
  14.  
  15. class TableRows extends RecursiveIteratorIterator {
  16. function __construct($it) {
  17. parent::__construct($it, self::LEAVES_ONLY);
  18. }
  19.  
  20. function current() {
  21. return "<td style='width: 150px; border: 1px solid black;'>" .
  22. parent::current(). "</td>";
  23. }
  24.  
  25. function beginChildren() {
  26. echo "<tr>";
  27. }
  28.  
  29. function endChildren() {
  30. echo "</tr>" . "n";
  31. }
  32. }
  33.  
  34. $servername = "localhost";
  35. $username = "root";
  36. $password = "";
  37. $dbname = "OACA";
  38.  
  39. try {
  40. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username,
  41.  
  42. $password);
  43. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  44. $stmt = $conn->prepare("SELECT * FROM etat");
  45. $stmt->execute();
  46.  
  47. // set the resulting array to associative
  48. $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  49.  
  50. foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
  51. echo $v;
  52. }
  53. }
  54. catch(PDOException $e) {
  55. echo "Error: " . $e->getMessage();
  56. }
  57. $conn = null;
  58. echo "</table>";
  59. ?>
  60. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement