Guest User

Untitled

a guest
Nov 18th, 2018
144
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. echo "<table style='border: solid 1px black;'>";
  3. echo "<tr><th>customer id </th><th>Description</th><th>Grade</th>
  4. <th>Qty</th><th>price</th><th>Tax amount</th></tr>";
  5. class TableRows extends RecursiveIteratorIterator {
  6. function __construct($it) {
  7. parent::__construct($it, self::LEAVES_ONLY);
  8. }
  9. function current() {
  10. return "<td style='width:150px;border:1px solid black;'>" .
  11. parent::current(). "</td>";
  12. }
  13. function beginChildren() {
  14. echo "<tr>";
  15. }
  16. function endChildren() {
  17. echo "</tr>" . "n";
  18. }
  19. }
  20. $servername = "localhost";
  21. $username = "root";
  22. $password = "";
  23. $dbname = "datatest";
  24. try {
  25. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username,
  26. $password);
  27. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  28. $stmt = $conn->prepare("SELECT product_customer,description,grade,qty,price, FROM
  29. data_table LIMIT 20");
  30. $stmt->execute();
  31. // set the resulting array to associative
  32. $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  33. foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as
  34. $k=>$v) {
  35. echo $v;
  36. }
  37. }
  38. catch(PDOException $e) {
  39. echo "Error: " . $e->getMessage();
  40. }
  41. $conn = null;
  42. echo "</table>";
  43. ?>
Add Comment
Please, Sign In to add comment