| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <!doctype html>
- <html lang="en">
- <head>
- <!-- Required meta tags -->
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
- <!-- Bootstrap CSS -->
- <link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
- <title>Racing Australia</title>
- </head>
- <body>
- <div class="container">
- <h1>Racing Australia</h1>
- <?php
- require_once 'dbconfig.php';
- $dsn = "pgsql:host=$host;port=5432;dbname=$db;user=$username;password=$password";
- try{
- // create a PostgreSQL database connection
- $conn = new PDO($dsn);
- // display a message if connected to the PostgreSQL successfully
- if($conn){
- echo "Connected to the <strong>$db</strong> database successfully!";
- }
- try {
- $date = new DateTime("now", new DateTimeZone('Australia/Melbourne'));
- } catch (Exception $e) {
- echo $e->getMessage();
- exit(1);
- }
- $query = sprintf("SELECT * FROM horses JOIN race_program
- ON horses.race_date = race_program.race_date
- AND horses.venue = race_program.venue
- AND horses.race = race_program.race
- WHERE horses.race_date >= %s
- ORDER BY horses.race_date, horses.venue, horses.race, horses.horse_no;", $conn->quote($date->format('Y-m-d')));
- $stmt = $conn->query($query);
- /*
- $r = $stmt->fetch(PDO::FETCH_ASSOC);
- print "<pre>" ;
- print_r($r);
- print "</pre>";
- */
- $query = sprintf("SELECT * FROM race_program
- WHERE race_date >= %s AND torn = TRUE
- ORDER BY race_date, venue, race DESC;", $conn->quote($date->format('Y-m-d')));
- $stmt2 = $conn->query( $query );
- ?>
- <table class="table table-striped table-bordered">
- <caption>Races featured on Torn</caption>
- <thead>
- <tr>
- <th>venue</th>
- <th>state</th>
- <th>date</th>
- <th>race</th>
- <th>start</th>
- <th>utc</th>
- </tr>
- </thead>
- <tbody>
- <?php
- while ( $row = $stmt2->fetch( PDO::FETCH_ASSOC ) ) : ?>
- <tr>
- <!-- <td><?php // echo htmlspecialchars($row['id']); ?></td> -->
- <td><?php echo htmlspecialchars($row['venue']); ?></td>
- <td><?php echo htmlspecialchars($row['state']); ?></td>
- <td><?php echo htmlspecialchars($row['race_date']); ?></td>
- <td><?php echo htmlspecialchars($row['race']); ?></td>
- <td><?php echo htmlspecialchars(substr($row['start_time'], 0, -3)); ?></td>
- <td><?php $t = strtotime($row['utctime']); echo gmdate('H:i', $t); ?></td>
- </tr>
- <?php endwhile; ?>
- </tbody>
- </table>
- <?php
- $query = sprintf("SELECT * FROM race_program
- WHERE race_date >= %s ORDER BY race_date, venue, race DESC;", $conn->quote($date->format('Y-m-d')));
- $stmt3 = $conn->query( $query );
- ?>
- <table class="table table-striped table-bordered">
- <caption>All races</caption>
- <thead>
- <tr>
- <th>venue</th>
- <th>state</th>
- <th>date</th>
- <th>race</th>
- <th>start</th>
- <th>utc</th>
- </tr>
- </thead>
- <tbody>
- <?php
- while ( $row = $stmt3->fetch( PDO::FETCH_ASSOC ) ) : ?>
- <tr>
- <!-- <td><?php // echo htmlspecialchars($row['id']); ?></td> -->
- <td><?php echo htmlspecialchars($row['venue']); ?></td>
- <td><?php echo htmlspecialchars($row['state']); ?></td>
- <td><?php echo htmlspecialchars($row['race_date']); ?></td>
- <td><?php echo htmlspecialchars($row['race']); ?></td>
- <td><?php echo htmlspecialchars(substr($row['start_time'], 0, -3)); ?></td>
- <td><?php $t = strtotime($row['utctime']); echo gmdate('H:i', $t); ?></td>
- </tr>
- <?php endwhile; ?>
- </tbody>
- </table>
- <table class="table table-striped table-bordered">
- <?php
- $table_head = <<<TABLEHEAD
- <thead>
- <tr>
- <!-- <th>id</th> -->
- <th>venue</th>
- <th>state</th>
- <th>date</th>
- <th>race</th>
- <th>start</th>
- <th>utc</th>
- <th>horse</th>
- <th>torn</th>
- </tr>
- </thead>
- <tbody>
- TABLEHEAD;
- $table_foot = <<<TABLEFOOT
- </tbody>
- TABLEFOOT;
- echo( $table_head );
- $new_venue = '';
- $new_day = '';
- $img = '48px-Commons-emblem-success.svg.png';
- $img = <<<'TAG'
- <img alt="File:Commons-emblem-success.svg"
- src="//upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Commons-emblem-success.svg/48px-Commons-emblem-success.svg.png"
- width="24"
- height="24" />
- TAG;
- $head_displayed = False;
- while($row = $stmt->fetch(PDO::FETCH_ASSOC)) : ?>
- <?php
- if ( $new_day != '' ) {
- if ( $new_day != $row['race_date'] ) {
- echo '</table>';
- echo '<h4>' . htmlspecialchars($row['race_date']) . '</h4>';
- echo ' <table class="table table-striped table-bordered">';
- $new_day = $row['race_date'];
- $head_displayed = True;
- }
- } else {
- $new_day = $row['race_date'];
- }
- if ( $new_venue != '' ) {
- if ( $new_venue != $row['venue'] ) {
- echo $table_foot;
- echo $table_head;
- $new_venue = $row['venue'];
- }
- } else {
- $new_venue = $row['venue'];
- }
- ?>
- <tr>
- <!-- <td><?php // echo htmlspecialchars($row['id']); ?></td> -->
- <td><?php echo htmlspecialchars($row['venue']); ?></td>
- <td><?php echo htmlspecialchars($row['state']); ?></td>
- <td><?php echo htmlspecialchars($row['race_date']); ?></td>
- <td><?php echo htmlspecialchars($row['race']); ?></td>
- <td><?php echo htmlspecialchars(substr($row['start_time'], 0, -3)); ?></td>
- <td><?php $t = strtotime($row['utctime']); echo gmdate('H:i', $t); ?></td>
- <td><?php echo htmlspecialchars($row['horse_no'] . ' ' . $row['horse_display_name']); ?></td>
- <td><?php if ($row['torn']) { echo $img; }; ?></td>
- </tr>
- <?php endwhile; ?>
- </table>
- <?php
- echo $table_foot;
- }catch (PDOException $e){
- // report error message
- echo $e->getMessage();
- }
- ?>
- </div>
- <!-- Optional JavaScript -->
- <!-- jQuery first, then Popper.js, then Bootstrap JS -->
- <script src="//code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
- <script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
- <script src="//stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
- </body>
- </html>
|