Scoop -- the swiss army chainsaw of content management
Front Page · Everything · News · Code · Help! · Wishlist · Project · Scoop Sites · Dev Notes · Latest CVS changes · Development Activities
Coutning Hits With In Scoop New Code
By bbatchel , Section Code []
Posted on Sun Feb 18, 2001 at 12:00:00 PM PST
One of the latest things I have implemented in my scoop site is a hit counter.

I figured what better place to do it than in the same mysql database that scoop runs in. Below I will run through how to set one of these up in your own site.

The first thing we need to do is create the table in mysql. So log into the mysql client and issue the following create table statement:

create table hits(
   hid char(20),
   hits int(11));

Next we create a box which will do the following:
  • If an entry for today's date exists in the table, increment it by one.
  • If an entry for today's date does not exist, create an entry.
  • Sum all of the previous hits for the total hit count.
The code for this:
my $content;

my ($rv, $sth) = $S->db_select({
    WHAT => 'hits',
    FROM => 'hits',
    WHERE => 'hid = curdate()+0'});

if ($rv == 0)
{
   $S->db_insert({
   INTO => 'hits',
   COLS => 'hid, hits',
   VALUES => 'curdate()+0, 0'});
}

$S->db_update({
    WHAT => 'hits',
    SET => 'hits = hits + 1',
    WHERE => 'hid = curdate()+0'});

my ($rv, $sth) = $S->db_select({
    WHAT => 'hits',
    FROM => 'hits',
    WHERE => 'hid = curdate()+0'});

my $hitstoday = $sth->fetchrow_hashref();

$content = qq{$hitstoday->{hits} hits today};

my ($rv, $sth) = $S->db_select({
    WHAT => 'sum(hits) as hits',
    FROM => 'hits'});

my $hitstodate = $sth->fetchrow_hashref();

$content .= qq{, $hitstodate->{hits} hits since we started counting...};


return {content => $content};
And that's really it. For my site, I embedded this into the header for all pages, and used a blank box template (just make a block that only contains |content| and name it empty_box). When I upgraded to CVS the other day, I found that executing boxes inside of included blocks (like the header block) was kind of iffy, so I have since moved the header code into each of the templates themselves...I only mention this if you run into this problem yourself.

If you would like to see what this looks like in action, just go to my site - its on every page.
< Supermojo and Ratings Visibility | Scoop Tuning >

Menu
· create account
· faq
· search
· report bugs
· Scoop Administrators Guide
· Scoop Box Exchange

Login
Make a new account
Username:
Password:

Related Links
· Scoop
· my scoop site
· More on New Code
· Also by bbatchel

Story Views
  12 Scoop users have viewed this story.

Display: Sort:
Coutning Hits With In Scoop | 4 comments (4 topical, 0 hidden)
Looks good.. (none / 0) (#1)
by Mystic on Mon Feb 19, 2001 at 09:24:56 PM PST

Looks like a nice feature to have in scoop. Andrew or rusty might want to add this to the scoop CVS if they think it is inline with the scoop working.



is this redundant? (none / 0) (#2)
by kellan on Thu Feb 22, 2001 at 10:18:29 PM PST

Is all this info already in the access logs waiting to be mined? And if not, how hard would it be to add I wonder? I'm inclined to think this sort of work would be done offline, but maybe a scoop url isn't definitive enough?

kellan



Payday Loans (none / 0) (#3)
by Pervez on Sat Apr 21, 2018 at 04:16:30 AM PST

I really believe which you understand the way to develop folks look closely at just what you must enunciate, specifically using a problem that's thus important. Today just click here Payday Loans I will be pleased to advise this website.



bathroom remodeling brooklyn (none / 0) (#4)
by Pervez on Sun Apr 07, 2019 at 12:19:53 PM PST

Be thankful using the enjoyable blog. It absolutely was useful for me. Right now, I'm thrilled We came across your site. Be thankful meant for providing around. Currently just click right here bathroom remodeling brooklyn After I way too usually research something brand-new via your own write-up.



Coutning Hits With In Scoop | 4 comments (4 topical, 0 hidden)
Display: Sort:

Hosted by ScoopHost.com Powered by Scoop
All trademarks and copyrights on this page are owned by their respective companies. Comments are owned by the Poster. The Rest © 1999 The Management

create account | faq | search