Page 1 of 1

PHP Web Counter

Posted: Sun Mar 25, 2007 1:48 pm
by Jonah Bron
Hi,

I was wondering what I should start on, to make a site counter. I have something, but don't know how to put it in motion:

Code: Select all

<?php

$sitecount = "1";
//take current value of text box, and add one

$sitecount + 1;

?>
The $sitecount = "1"; is supposed to be something like $sitecount = $value;, but I don't know how to take the value from the box, to this php tag, without the user having to submit a form, and without a second page loading. Once this counter is in action, it will be no problem to make it add to the value, but I don't know how to get it started. Any help would be much appreciated.

Posted: Sun Mar 25, 2007 2:32 pm
by Christopher
You need somewhere to store the data. Take a look at what databases you web serve supports (e.g. MySQL or SQLite) choose one of those. There should be examples around the web if you search.

Posted: Sun Mar 25, 2007 3:59 pm
by Jonah Bron
Thanks, arborint. I contacted my web server, and he said it does have a MySQL database. I find it strange that you can not just add on to the current value every time the page is visited. Something like below. Should I do a Google Code search?

Thanks so much

Posted: Sun Mar 25, 2007 4:05 pm
by Skara
yes. always google, then ask. ;)

try 'mysql tutorial' or 'php mysql tutorial'

Posted: Sun Mar 25, 2007 5:02 pm
by Christopher
You might also want to check phpclasses.org and other script sites for counters. There also might be some file based one that deal with the locking issues to make increments atomic that the databases take care of for you.