Advertisement
Guest User

Untitled

a guest
Sep 9th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <?php
  2. echo "<table style='border: solid 0px blue: align= center;'>";
  3. echo "<tr><th>USER ID</th><th> DESCRIPTION</th><th> TOTAL CAPITAL</th></tr>";
  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: 1200px; 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 = "bitcer";
  25. $password = "45dflookokd";
  26. $dbname = "bitcoiunt";
  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 name, capitalinfo, capital FROM tbl_registered_users");
  32. $stmt->execute();
  33.  
  34. // set the resulting array to associative
  35. $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  36.  
  37. foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
  38. echo $v;
  39. }
  40. }
  41. catch(PDOException $e) {
  42. echo "Error: " . $e->getMessage();
  43. }
  44. $conn = null;
  45. echo "</table>";
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement