index.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <!-- Required meta tags -->
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7. <!-- Bootstrap CSS -->
  8. <link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  9. <title>Racing Australia</title>
  10. </head>
  11. <body>
  12. <div class="container">
  13. <h1>Racing Australia</h1>
  14. <?php
  15. require_once 'dbconfig.php';
  16. $dsn = "pgsql:host=$host;port=5432;dbname=$db;user=$username;password=$password";
  17. try{
  18. // create a PostgreSQL database connection
  19. $conn = new PDO($dsn);
  20. // display a message if connected to the PostgreSQL successfully
  21. if($conn){
  22. echo "Connected to the <strong>$db</strong> database successfully!";
  23. }
  24. $date = new DateTime("now", new DateTimeZone('Australia/Melbourne') );
  25. $query = sprintf("SELECT * FROM horses JOIN race_program
  26. ON horses.race_date = race_program.race_date
  27. AND horses.venue = race_program.venue
  28. AND horses.race = race_program.race
  29. WHERE horses.race_date >= %s
  30. ORDER BY horses.race_date, horses.venue, horses.race;", $conn->quote($date->format('Y-m-d')));
  31. $stmt = $conn->query($query);
  32. /*
  33. $r = $stmt->fetch(PDO::FETCH_ASSOC);
  34. print "<pre>" ;
  35. print_r($r);
  36. print "</pre>";
  37. */
  38. ?>
  39. <table class="table table-striped table-bordered">
  40. <?php
  41. $table_head = <<<TABLEHEAD
  42. <thead>
  43. <tr>
  44. <!-- <th>id</th> -->
  45. <th>venue</th>
  46. <th>state</th>
  47. <th>date</th>
  48. <th>race</th>
  49. <th>start</th>
  50. <th>utc</th>
  51. <th>horse</th>
  52. <th>torn</th>
  53. </tr>
  54. </thead>
  55. <tbody>
  56. TABLEHEAD;
  57. $table_foot = <<<TABLEFOOT
  58. </tbody>
  59. TABLEFOOT;
  60. echo( $table_head );
  61. $new_venue = '';
  62. $new_day = '';
  63. $img = '48px-Commons-emblem-success.svg.png';
  64. $img = '<img alt="File:Commons-emblem-success.svg" src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Commons-emblem-success.svg/48px-Commons-emblem-success.svg.png" decoding="async" width="24" height="24" srcset="https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Commons-emblem-success.svg/72px-Commons-emblem-success.svg.png 1.5x, https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Commons-emblem-success.svg/96px-Commons-emblem-success.svg.png 2x" data-file-width="48" data-file-height="48">';
  65. $head_displayed = False;
  66. while($row = $stmt->fetch(PDO::FETCH_ASSOC)) : ?>
  67. <?php
  68. if ( $new_day != '' ) {
  69. if ( $new_day != $row['race_date'] ) {
  70. echo '</table>';
  71. echo '<h4>' . htmlspecialchars($row['race_date']) . '</h4>';
  72. echo ' <table class="table table-striped table-bordered">';
  73. $new_day = $row['race_date'];
  74. $head_displayed = True;
  75. }
  76. } else {
  77. $new_day = $row['race_date'];
  78. }
  79. if ( $new_venue != '' ) {
  80. if ( $new_venue != $row['venue'] ) {
  81. echo $table_foot;
  82. echo $table_head;
  83. $new_venue = $row['venue'];
  84. }
  85. } else {
  86. $new_venue = $row['venue'];
  87. }
  88. ?>
  89. <tr>
  90. <!-- <td><?php // echo htmlspecialchars($row['id']); ?></td> -->
  91. <td><?php echo htmlspecialchars($row['venue']); ?></td>
  92. <td><?php echo htmlspecialchars($row['state']); ?></td>
  93. <td><?php echo htmlspecialchars($row['race_date']); ?></td>
  94. <td><?php echo htmlspecialchars($row['race']); ?></td>
  95. <td><?php echo htmlspecialchars(substr($row['start_time'], 0, -3)); ?></td>
  96. <td><?php $t = strtotime($row['utctime']); echo gmdate('H:i', $t); ?></td>
  97. <td><?php echo htmlspecialchars($row['horse']); ?></td>
  98. <td><?php if ($row['torn']) { echo $img; }; ?></td>
  99. </tr>
  100. <?php endwhile; ?>
  101. </table>
  102. <?php
  103. echo $table_foot;
  104. }catch (PDOException $e){
  105. // report error message
  106. echo $e->getMessage();
  107. }
  108. ?>
  109. </div>
  110. <!-- Optional JavaScript -->
  111. <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  112. <script src="//code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  113. <script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  114. <script src="//stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  115. </body>
  116. </html>