PHP Web Counter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

PHP Web Counter

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post 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
Last edited by Jonah Bron on Sun Mar 25, 2007 5:32 pm, edited 1 time in total.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

yes. always google, then ask. ;)

try 'mysql tutorial' or 'php mysql tutorial'
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
Post Reply