Hi, I have a script and a MYSQL database monitoring the hits of my website. It outputs the daily uniques using this code:
I want to modify it so that it displays the monthly uniques for every month. This is what I did so far, but can't really do the hard part (query)PHP Code:function getWeeksHits() {
global $wpdb;
$dt = strtotime(gmdate("j F Y",time()+(((gmdate('I'))?($this->tz_offset+1):$this->tz_offset)*3600)));
$dt = $dt-(3600*2); // The above is off by two hours. Don't know why yet...
$tmp = "";
$dt_start = time();
$tmp = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n";
$tmp .= "\t<tr><th colspan=\"2\">Hits in the last 2weeks</th></tr>\n";
$tmp .= "\t<tr><td class=\"accent\">Day</td><td class=\"accent last\">Hits</td></tr>\n";
for ($i=0; $i<7; $i++) {
$dt_stop = $dt_start;
$dt_start = $dt - ($i * 60 * 60 * 24);
$day = ($i)?gmdate("l, j M Y",$dt_start):"Today, ".gmdate("j M Y",$dt_start);
$query = "SELECT COUNT(DISTINCT remote_ip) AS 'total' FROM $this->table_stats WHERE dt > $dt_start AND dt <=$dt_stop";
if ($total = $wpdb->get_var($query)) {
$tmp .= "\t<tr><td>$day</td><td class=\"last\">$total</td></tr>\n";
}
}
$tmp .= "</table>";
return $tmp;
}
PHP Code:function getMonthsHits() {
global $wpdb;
$dt = strtotime(gmdate("j F Y",time()+(((gmdate('I'))?($this->tz_offset+1):$this->tz_offset)*3600)));
$dt = $dt-(3600*2);
$tmp = "";
$dt_start = time();
$tmp = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n";
$tmp .= "\t<tr><th colspan=\"2\">Hits in the last 12 months</th></tr>\n";
$tmp .= "\t<tr><td class=\"accent\">Day</td><td class=\"accent last\">Hits</td></tr>\n";
for ($i=0; $i<12; $i++) {
$dt_stop = $dt_start;
$dt_start = $dt - ($i * 60 * 60 * 24);
$month = ($i)?gmdate("F, M Y",$dt_start):gmdate("F, M Y",$dt_start);
$query = "SELECT COUNT(DISTINCT remote_ip) AS 'total' FROM $this->table_stats WHERE dt > $dt_start AND dt <=$dt_stop";
if ($total = $wpdb->get_var($query)) {
$tmp .= "\t<tr><td>$month</td><td class=\"last\">$total</td></tr>\n";
}
}
$tmp .= "</table>";
return $tmp;
}



Bookmarks