Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- echo "<table style='border: solid 1px black;'>";
- echo "<tr><th>customer id </th><th>Description</th><th>Grade</th>
- <th>Qty</th><th>price</th><th>Tax amount</th></tr>";
- class TableRows extends RecursiveIteratorIterator {
- function __construct($it) {
- parent::__construct($it, self::LEAVES_ONLY);
- }
- function current() {
- return "<td style='width:150px;border:1px solid black;'>" .
- parent::current(). "</td>";
- }
- function beginChildren() {
- echo "<tr>";
- }
- function endChildren() {
- echo "</tr>" . "n";
- }
- }
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "datatest";
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username,
- $password);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $stmt = $conn->prepare("SELECT product_customer,description,grade,qty,price, FROM
- data_table LIMIT 20");
- $stmt->execute();
- // set the resulting array to associative
- $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
- foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as
- $k=>$v) {
- echo $v;
- }
- }
- catch(PDOException $e) {
- echo "Error: " . $e->getMessage();
- }
- $conn = null;
- echo "</table>";
- ?>
Add Comment
Please, Sign In to add comment