Hi!

Ive tried to install a counter-script that displays the number of pageloads on my forum. The forum is made in php and are using mysql-database to store the articles that are possible to submit on the site. Ive tried several different counters which have used the “include” command to include the script on the page, in my case content.php.

The problem is that the counter are counting the total number of pageloads on all of the articles alltogether, instead of counting the number of pageloads on every unique article. The page that are calling the articles from the database are as I said content.php and every article are named content.php?article.1, content.php?article.2, content.php?article.3 etc. the number refering to the number in the database.

My question is:

Are there anyone who got a script or any suggestion on how I can manage to view the number of pageloads on every unique article? I just manage to view the total amount of pageloads.

I guess I, somehow have to have a unique code for each article but the prolem is how and what kind of code?

Hope you understood my problem.

Thanks for your help

Per

    One way to achieve this is to have a column in the article table to show the number of times it has been displayed, and then in your display logic update that column every time you show that article.

      Ok!

      Thanks for reply! Where shall I do this? What kind of table do you mean? An ordinary html table for displaying the function? The problem is the function. Maybe I missunderstood. Im not very good in programming.

      what is logic update?

      Do you have any code example?

      Tha code Im using right now is:
      (but it dont work for counting the pageloads on each unique articles, it displays the total amount of pageloads)

      Its a free script from www.adamarkdesign.com

      <?php
      /*


      PHP Multipage Counter



      Written by:
      Adam Stout (Adam@adamarkdesign.com)
      www.adamarkdesign.com

      Version 1.5
      11/25/00



      To install insert this code into your PHP page:

      $display="Yes"; include("counter/counter.php");

      Be sure to change this to the relative location
      of the script.

      Set $display to yes or no to have counter display
      or just print number in the code as a comment.
      (If not set, defaults to yes)


      Directory counter.php is in must have permissions
      set to 777 on UNIX machine.


      */

      $counterfile = $DOCUMENT_ROOT.'/counter/'.ereg_replace( "/", "_", $PHP_SELF);

      if (!file_exists($counterfile)) {
      // Start Counter at 5000
      $count=4999; //Will get ++ before being printed
      $initial = $count + 1;
      // Success Message
      echo "Congrats. Your Counter File Successfully Created.<BR>";
      echo "Your counter has been initialized to $initial<BR>";
      echo "To change the counter simply modify the counter file:<BR>";
      echo "$counterfile<BR>";
      }

      else {
      // Open Counter
      //open the file handler
      $fp=fopen("$counterfile","r");
      //Read the previous count
      $count=fgets($fp,1024);
      //close the file.
      fclose($fp);
      }
      $fw=fopen("$counterfile","w");
      //Increment the counter
      $pageviews=$count+1;
      //write the counter back to the log file ie., acc.txt
      $countnew=fputs($fw,$count+1);

      //Display counter
      if ($display != "No") {
      	echo $pageviews;
      } else {
      	echo "<!-- This page has been viewed $pageviews times. -->";
      }
      fclose($fw); 

      ?>

      thanks

      Perik

        Write a Reply...