Skip to content

Instantly share code, notes, and snippets.

@evanpurkhiser
Forked from RSquaredSoftware/gist:2411307
Created April 18, 2012 05:50
Show Gist options
  • Save evanpurkhiser/2411356 to your computer and use it in GitHub Desktop.
Save evanpurkhiser/2411356 to your computer and use it in GitHub Desktop.
<?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