Advertisement
deeejay

PostgreSQL - Use PHP to Output Data in HTML Table

Jun 14th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4. <title>Test</title>
  5. </head>
  6.  
  7. <body bgcolor="white">
  8.  
  9. <?php
  10. $link = pg_connect("host=db_host.org port=5432 dbname=db_name user=your_username password=your_password");
  11. $result = pg_exec($link, "select * from some_table");
  12. $numrows = pg_numrows($result);
  13. echo "<p>link = $link<br>
  14. result = $result<br>
  15. numrows = $numrows</p>
  16. ";
  17. ?>
  18.  
  19. <table border="1">
  20. <tr>
  21. <th>Last name</th>
  22. <th>First name</th>
  23. <th>ID</th>
  24. </tr>
  25. <?php
  26.  
  27. // Loop on rows in the result set.
  28.  
  29. for($ri = 0; $ri < $numrows; $ri++) {
  30. echo "<tr>\n";
  31. $row = pg_fetch_array($result, $ri);
  32. echo " <td>", $row["first_name"], "</td>
  33. <td>", $row["last_name"], "</td>
  34. <td>", $row["id"], "</td>
  35. </tr>
  36. ";
  37. }
  38. pg_close($link);
  39. ?>
  40. </table>
  41.  
  42. </body>
  43.  
  44. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement