Page 1 of 1
Hit Counter
Posted: Fri Sep 23, 2005 6:00 pm
by vchris
How would I create a hit counter that works with a db.
I tried to create one where everytime a user opened the index.php page it updated the countid value by 1 and then I was doing a select to display the countid but it didn't really work and I'm sure there is an easier way.
Anyone got an idea?
Posted: Fri Sep 23, 2005 6:26 pm
by feyd
rough idea
Code: Select all
$q = mysql_query('SELECT `viewCount` FROM `pageViews` WHERE `pageID` = \'23\'') or die(mysql_error());
$count = mysql_fetch_assoc($q);
$count = intval(array_shift($count))+1;
$u = mysql_query('UPDATE `pageViews` SET `viewCount` = `viewCount` + 1 WHERE `pageID` = \'23\'') or die(mysql_error());
echo $count;
where 23 is the ID you've given the "this" page..
oops... made some boo-boos on the code.
Posted: Fri Sep 23, 2005 6:40 pm
by vchris
So the record pageid would by a different id for every page in my site so I can know where all the users are going?
Posted: Fri Sep 23, 2005 6:59 pm
by feyd
depending on how you do logging yes.. but the counter will merely count for each page id you give it..
Posted: Fri Sep 23, 2005 7:44 pm
by vchris
It works perfectly!
Thanks buddy!