//change next line to access your mysql database
$db = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$db) {
die('Could not connect: ' . mysql_error());
}
//change the end of the next line to be the starting date of your statistics
$start = date('dmY',mktime(0, 0, 0,mm,dd,yyyy);
$counter = 1;
$totals;
//next we add in todays results
$query = "SELECT count(*), web_page FROM LinkStatistics WHERE countrycode = 'US' GROUP BY web_page";
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
{
$totals[$row[1]] = $row[0];
}
//now start adding previous days
while($start != date('dmY', strtotime("-$counter days")))
{
$table = "LinkStatistics".date('dmY', strtotime("-$counter days"));
$query = "SELECT count(*), web_page FROM ".$table" WHERE countrycode = 'US' GROUP BY web_page";
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
{
//if else just in case you have other sites not included in the original days data
if(isset($totals[$row[1]]))
$totals[$row[1]] += $row[0];
else
$totals[$row[1]] = $row[0];
}
$counter++;
}
echo "<table><tr><th>Website Name</th><th>$total</th></tr>";
foreach($totals as $key => $value)
{
echo "<tr><td>".$key."</td><td>".$value."</td></tr>";
}
echo "</table>";
mysql_close($db);
|