index.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. $query = sprintf("SELECT * FROM horses JOIN race_program
  25. ON horses.race_date = race_program.race_date
  26. AND horses.venue = race_program.venue
  27. AND horses.race = race_program.race
  28. WHERE horses.race_date >= %s
  29. ORDER BY horses.race_date, horses.venue, horses.race;", $conn->quote(date("Y-m-d")));
  30. $stmt = $conn->query($query);
  31. /*
  32. $r = $stmt->fetch(PDO::FETCH_ASSOC);
  33. print "<pre>" ;
  34. print_r($r);
  35. print "</pre>";
  36. */
  37. ?>
  38. <table class="table table-striped table-bordered">
  39. <?php
  40. $table_head = <<<TABLEHEAD
  41. <thead>
  42. <tr>
  43. <!-- <th>id</th> -->
  44. <th>venue</th>
  45. <th>state</th>
  46. <th>race_date</th>
  47. <th>race</th>
  48. <th>start</th>
  49. <th>horse</th>
  50. </tr>
  51. </thead>
  52. <tbody>
  53. TABLEHEAD;
  54. $table_foot = <<<TABLEFOOT
  55. </tbody>
  56. TABLEFOOT;
  57. echo( $table_head );
  58. $new_venue = '';
  59. $new_day = '';
  60. $head_displayed = False;
  61. while($row = $stmt->fetch(PDO::FETCH_ASSOC)) : ?>
  62. <?php
  63. if ( $new_day != '' ) {
  64. if ( $new_day != $row['race_date'] ) {
  65. echo '</table>';
  66. echo '<h4>' . htmlspecialchars($row['race_date']) . '</h4>';
  67. echo ' <table class="table table-striped table-bordered">';
  68. $new_day = $row['race_date'];
  69. $head_displayed = True;
  70. }
  71. } else {
  72. $new_day = $row['race_date'];
  73. }
  74. if ( $new_venue != '' ) {
  75. if ( $new_venue != $row['venue'] ) {
  76. echo $table_foot;
  77. echo $table_head;
  78. $new_venue = $row['venue'];
  79. }
  80. } else {
  81. $new_venue = $row['venue'];
  82. }
  83. ?>
  84. <tr>
  85. <!-- <td><?php echo htmlspecialchars($row['id']); ?></td> -->
  86. <td><?php echo htmlspecialchars($row['venue']); ?></td>
  87. <td><?php echo htmlspecialchars($row['state']); ?></td>
  88. <td><?php echo htmlspecialchars($row['race_date']); ?></td>
  89. <td><?php echo htmlspecialchars($row['race']); ?></td>
  90. <td><?php echo htmlspecialchars($row['start_time']); ?></td>
  91. <td><?php echo htmlspecialchars($row['horse']); ?></td>
  92. </tr>
  93. <?php endwhile; ?>
  94. </table>
  95. <?php
  96. echo $table_foot;
  97. }catch (PDOException $e){
  98. // report error message
  99. echo $e->getMessage();
  100. }
  101. ?>
  102. </div>
  103. <!-- Optional JavaScript -->
  104. <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  105. <script src="//code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  106. <script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  107. <script src="//stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  108. </body>
  109. </html>