-
-
Save evanpurkhiser/2411356 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach ($games as $game) | |
{ | |
// The default values array.. all empty | |
$default = array_combine($games, array_fill(0, length($games), '-')); | |
try | |
{ | |
$sth = $dbh->prepare("SELECT * FROM $game ORDER BY date $sort"); | |
$sth->execute(); | |
$data = $sth->fetchAll(PDO::FETCH_ASSOC); | |
foreach ($data as $row) | |
{ | |
// Get the date for this value | |
$date = array_shift($row); | |
// Get the comma separated values for this dates pick | |
$value = implode(',', $row); | |
// Get the other original values for the date | |
$previous = isset($result[$date]) ? $result[$date] : $default; | |
// Add these new game results to the array | |
$result[$date] = array_merge($previous, array($game => $value)); | |
// Sort the array by the keys to ensure they're always in the same order | |
ksort($result[$date]); | |
} | |
} | |
catch (PDOException $e) | |
{ | |
die("Printing Data Error: ". $e->getMessage()); | |
} | |
} | |
?> | |
<html> | |
<body> | |
<table> | |
<thead> | |
<tr> | |
<th>Date</th> | |
<? foreach (current($result) as $column_name => $values): ?> | |
<th><?= $column_name; ?></th> | |
<? endforeach; ?> | |
</tr> | |
</thead> | |
<tbody> | |
<? foreach ($result as $date => $results): ?> | |
<tr> | |
<td><?= $date; ?></td> | |
<? foreach ($results as $game => $balls): ?> | |
<td><?= $balls; ?></td> | |
<? endforeach; ?> | |
</tr> | |
<? endforeach; ?> | |
</tbody> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment