Jump to content
xisto Community
Sign in to follow this  
iGuest

page counts

Recommended Posts

Can anyone tell me how i would go about using PHP & MySQL to count hits on a certain page.ie. someone loads page.php and "1" is added to the value in my mySQL dbthank you

Share this post


Link to post
Share on other sites

assuming you've already connected to the db...

<?//EDIT$table = tablename;$id = a unique number or something to define what page you are counting the hits on;//end Edit$hitcount = mysql_query("SELECT hits FROM $table WHERE id = $id LIMIT 1");while($count=mysql_fetch_array($hitcount)) {$hit_count = $count['hits'] + 1;}Print $hit_count;print " people have visited";$update = mysql_query("UPDATE $table SET hits = $hit_count WHERE id='$id'");?>

Create a table with the fields id and hits ... you'll have to adjust this...its just a guide

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.