<html>
<head>
<title>Hit counter</title>
</head>
<body>
<?php
$db = mysql_connect('localhost', 'e2freader', 'readme') or die(mysql_error());

mysql_select_db('e2f', $db) or die(mysql_error());

$format = "%Y%m%d000000";

$today = strftime($format);

$r = mysql_query("select count(distinct ip) as u, count(ip) as t from hits");
$set = mysql_fetch_assoc($r);

$u = $set['u'];
$t = $set['t'];
print "<h1>Total hits: $t</h1><h1>Unique hits: $u</h1>";

print "<h1>Hits for past 31 days (per day)</h1>";

for($time = strtotime('now'); $time > strtotime('-1 month'); $time = strtotime('-1 day', $time))
{
  $date = strftime('%Y-%m-%d', $time);

  $thisday = $date;

  //$nextday = strftime('%Y%m%d000000', strtotime('+1 day', $time));

  $uhits[$date] = mysql_query("select comic as comic, count(distinct ip) as uc, count(ip) as cc from hits where date like '$thisday %' group by comic", $db) or die(mysql_error());

  while($row = mysql_fetch_assoc($uhits[$date]))
    {
      $uniques[$date][substr($row['comic'], 0, 10)] = $row['uc'];
      $total[$date][substr($row['comic'], 0, 10)] = substr($row['cc'], 0, 8);
    }

  print "<table border=\"1\" style=\"border-style: double\" cellspacing=\"0\">";
  print "<tr><td colspan=\"3\">Date: $date</td></tr>";
  print "<tr>";
  print "<td><strong>Comic</strong></td>";
  print "<td><strong>Uniques<strong></td>";
  print "<td><strong>Total</strong></td>";
  print "</tr>";

  if(isset($uniques[$date]))
    {
      foreach($uniques[$date] as $comic => $count)
	{
	  $tcount = $total[$date][$comic];
	  print "<tr><td>$comic</td><td>$count</td><td>$tcount</td></tr>";
	}
    }

  print "</table><br>";
}

?>
</body>
</html>