Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?php
  2. echo "<table style='border: solid 1px black;'>";
  3. echo "<tr><th>Voornaam</th><th>tussenvoegsel</th><th>achternaam</th><th>email</th>";
  4.  
  5. class TableRows extends RecursiveIteratorIterator {
  6. function __construct($it) {
  7. parent::__construct($it, self::LEAVES_ONLY);
  8. }
  9.  
  10. function current() {
  11. return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
  12. }
  13.  
  14. function beginChildren() {
  15. echo "<tr>";
  16. }
  17.  
  18. function endChildren() {
  19. echo "</tr>" . "\n";
  20. }
  21. }
  22.  
  23. $servername = "localhost";
  24. $username = "root";
  25. $password = Null;
  26. $dbname = "kaasfondue";
  27.  
  28. try {
  29. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  30. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  31. $stmt = $conn->prepare("SELECT * FROM users");
  32. $stmt->execute();
  33.  
  34. // associate met tabel
  35. $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  36. foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
  37. echo $v;
  38. }
  39. }
  40. catch(PDOException $e) {
  41. echo "Error: " . $e->getMessage();
  42. }
  43. $conn = null;
  44. echo "</table>";
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement