daily pastebin goal
73%
SHARE
TWEET

Untitled

a guest Mar 19th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <body>
  5. echo "<table style='border: solid 1px black;'>";
  6.  echo "<tr><th>Id</th><th>Firstname</th><th>Lastname</th></tr>";
  7.  
  8. class TableRows extends RecursiveIteratorIterator {
  9.     function __construct($it) {
  10.         parent::__construct($it, self::LEAVES_ONLY);
  11.     }
  12.  
  13.     function current() {
  14.         return "<td style='width: 150px; border: 1px solid black;'>" .
  15.     parent::current(). "</td>";
  16.     }
  17.  
  18.     function beginChildren() {
  19.         echo "<tr>";
  20.     }
  21.  
  22.     function endChildren() {
  23.         echo "</tr>" . "n";
  24.     }
  25. }
  26.  
  27. $servername = "";
  28. $username = "";
  29. $password = "";
  30. $dbname = "";
  31.  
  32. try {
  33.     $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  34.     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  35.     $stmt = $conn->prepare("SELECT Team_ID, Name FROM Team");
  36.     $stmt->execute();
  37.  
  38.     // set the resulting array to associative
  39.     $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  40.  
  41.     foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
  42.         echo $v;
  43.     }
  44. }
  45. catch(PDOException $e) {
  46.     echo "Error: " . $e->getMessage();
  47. }
  48. $conn = null;
  49. echo "</table>";
  50. ?>
  51.  
  52. </body>
  53. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top