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?
Hit Counter
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
rough idea
where 23 is the ID you've given the "this" page..
oops... made some boo-boos on the code.
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;oops... made some boo-boos on the code.
Last edited by feyd on Fri Sep 23, 2005 6:58 pm, edited 1 time in total.