Jump to content

Recommended Posts

I need a counter on my website that counts SEPERATE pages and shows them on one. I have a main "videos" page and need it to say: viewed <COUNTERCODEHERE> times on each of the videos on my table, but all the counters I have used only count the actual page its on. Basically, I need a counter that counts other pages rather than the one its on. Does anyone know of any good ones?
Link to comment
https://forums.phpfreaks.com/topic/11504-i-need-a-specific-type-of-counter/
Share on other sites

Just create a script that adds count for a page each time its executed. These must be stored in a database.

Then, retrieve the count(s) and display them on the other page.

Some people may suggest you to use MySQL as database, but if it's something small, you can use flatfiles, they work well too.
counters use a database to store the count. all you really have to do is create an extra column in your table called page or something, which will hold the name of the webpage. then in your counter script, update the table where page = '$PHP_SELF' sort of thing. That way, your table will have x rows for x pages and each one is updated individually.

as far as the display part of your counter, you would select pretty much the same. examples:

overall count:
[code]
select count(numhits) as total from table
[/code]
or maybe even
[code]
$sql = "select * from table";
$rs = mysql_query($rs);
$total = 0;
while ($list = mysql_fetch_array($rs)) {
   $total += $list['numhits'];
   echo "hits on " . $list['page'] . ": " . $list['numhits'] . "<br>";
}
echo "total hits: " . $total;
[/code]

edit: parrot beated me
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.