Browse Source

Split tables

Foppe Hemminga 6 năm trước cách đây
mục cha
commit
6451b2aff8
1 tập tin đã thay đổi với 23 bổ sung3 xóa
  1. 23 3
      index.php

+ 23 - 3
index.php

@@ -30,7 +30,8 @@
             ORDER BY race_date, venue, race;", $conn->quote(date("Y-m-d")));
 		$stmt = $conn->query($query);
 		// $r = $stmt->fetch(PDO::FETCH_ASSOC);
-    ?>
+
+    $table_head = <<<TABLEHEAD
     <table class="table table-striped table-bordered">
         <thead>
         <tr>
@@ -42,7 +43,22 @@
         </tr>
         </thead>
         <tbody>
-    <?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) : ?>
+TABLEHEAD;
+    echo( $table_head );
+    $new_venue = '';
+    $new_day = '';
+    while($row = $stmt->fetch(PDO::FETCH_ASSOC)) : ?>
+        <?php
+            if ( $new_day != '' && $new_day != $row['race_date'] ) {
+                echo $table_foot;
+                echo '<h4>' . htmlspecialchars($row['race_date']) . '</h4>';
+                echo $table_head;
+            } else if ( $new_venue != '' && $new_venue != $row['venue'] ) {
+                echo $table_foot;
+                echo $table_head;
+                $new_venue = $row['venue'];
+            }
+        ?>
     <tr>
         <td><?php echo htmlspecialchars($row['id']); ?></td>
         <td><?php echo htmlspecialchars($row['venue']); ?></td>
@@ -51,9 +67,13 @@
         <td><?php echo htmlspecialchars($row['horse']); ?></td>
     </tr>
 	<?php endwhile; ?>
+    <?php
+    $table_foot = <<<TABLEFOOT
         </tbody>
     </table>
-    <?php
+TABLEFOOT;
+    echo $table_foot;
+
     }catch (PDOException $e){
 		// report error message
 		echo $e->getMessage();