fortune.php 892 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <!DOCTYPE html>
  2. <html><head><title>Fortunes</title></head>
  3. <body>
  4. <table>
  5. <tr><th>id</th><th>message</th></tr>
  6. <?php table(); ?>
  7. </table>
  8. </body>
  9. </html><?php
  10. //
  11. // Database Test
  12. //
  13. function fortune() {
  14. // Database connection // TODO: use PDO once implemented
  15. $link = mysql_pconnect('tfb-database', 'benchmarkdbuser', 'benchmarkdbpass');
  16. mysql_select_db('hello_world', $link);
  17. // Store result in array.
  18. $result = mysql_query('SELECT id, message FROM Fortune', $link);
  19. $arr = array();
  20. while ($row = mysql_fetch_array($result)) {
  21. $arr[$row['id']] = $row['message'];
  22. }
  23. mysql_close($link);
  24. $arr[0] = 'Additional fortune added at request time.';
  25. asort($arr);
  26. return $arr;
  27. }
  28. function table() {
  29. foreach ( fortune() as $id => $fortune ) : ?>
  30. <tr><td><?= $id ?></td><td><?= htmlspecialchars($fortune, ENT_QUOTES, 'UTF-8') ?></td></tr>
  31. <?php endforeach;
  32. }