Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1.  
  2. <html>
  3. <body background="diamond.png">
  4. <center>
  5. <?php
  6. echo "<table style='border: solid 1px black;'>";
  7. echo "<tr><th>Player Name</th><th>Coins</th><th>Kills</th><th>Deaths</th></tr>";
  8.  
  9. class TableRows extends RecursiveIteratorIterator {
  10. function __construct($it) {
  11. parent::__construct($it, self::LEAVES_ONLY);
  12. }
  13.  
  14. function current() {
  15. return "<td style='width: 150px; border: 1px solid black;'>" . 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 = "localhost";
  28. $username = "abc";
  29. $password = "abc";
  30. $dbname = "abc";
  31. $table_prefix = "kitbattle_";
  32.  
  33. try {
  34. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  35. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  36. $stmt = $conn->prepare("SELECT player_name, Coins, Kills, Deaths FROM $table_prefix");
  37. $stmt->execute();
  38.  
  39. // set the resulting array to associative
  40. $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  41.  
  42. foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
  43. echo $v;
  44. }
  45. }
  46. catch(PDOException $e) {
  47. echo "Error: " . $e->getMessage();
  48. }
  49. $conn = null;
  50. echo "</table>";
  51. ?>
  52. </body>
  53. </center>
  54. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement