SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Non-Member
    Join Date
    Jan 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Monthly Unique Hits

    Hi, I have a script and a MYSQL database monitoring the hits of my website. It outputs the daily uniques using this code:

    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;
        } 
    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 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;
          } 

  2. #2
    Non-Member
    Join Date
    Jan 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone?

  3. #3
    Non-Member
    Join Date
    Jan 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •