Advertisement
Guest User

Untitled

a guest
Mar 8th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. <?php
  2. $USER = $_GET["userID"];
  3.  
  4. echo "<table style='border: solid 1px black;'>";
  5. echo "<tr><th>Message</th><th>Sender</th><th>TO</th></tr>";
  6.  
  7. class TableRows extends RecursiveIteratorIterator {
  8. function __construct($it) {
  9. parent::__construct($it, self::LEAVES_ONLY);
  10. }
  11.  
  12. function current() {
  13. return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
  14. }
  15.  
  16. function beginChildren() {
  17. echo "<tr>";
  18. }
  19.  
  20. function endChildren() {
  21. echo "</tr>" . "\n";
  22. }
  23. }
  24.  
  25. $servername = "localhost";
  26. $username = "ROOT";
  27. $password = "";
  28. $dbname = "chat";
  29.  
  30. try {
  31. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  32. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  33. $stmt = $conn->prepare("SELECT messageData, messageSender, messageUser FROM message, user WHER$
  34. $stmt->execute();
  35.  
  36. // set the resulting array to associative
  37. $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  38. foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
  39. echo $v;
  40. }
  41. }
  42. catch(PDOException $e) {
  43. echo "Error: " . $e->getMessage();
  44. }
  45. $conn = null;
  46. echo "</table>";
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement