How to make a php article counter?

how to make a php article counter?

  • I write some simple article scripts. Now I want add some article counter. If there have 3 possibility it should make an article counter. the article has been opened for read.(only one whole article per page, it will count 1 time) the article has been searched in a content search list(with title and short content description 5 items per page, it will count 1 time. then if open to read whole article content, it will count another 1 time.) the article has been showed in the home page by Random (with title and short description, it will count 1 time) Is there any good suggestion how to do these better? Which database design is better? put article and count number in one table? or make two tables? Can anyone recommend me some php article counter script, if the main rules write into a file like class.php then include into my every page. Thanks.

  • Answer:

    What you could do is use the database that auto increments and just increment that value when the page is viewed, and display that value if you want. Here is how you can setup the http://dev.mysql.com/doc/refman/4.1/en/example-auto-increment.html. Then update the "value" (you don't have to actually update anything it will AI) mysql_query("UPDATE COUNTER SET HITS = ''"); Then just display the view $result = mysql_query("SELECT * FROM PAGEVIEWS"); while($row = mysql_fetch_array($result)) { echo $row['COUNTER']; } This is off the top of my head - it should work.

cj333 at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

If you are counting the number of hits on an article, create a column and add one to it every time somebody accesses the page. Something like: $sql = "UPDATE table SET count=count+1 WHERE id='$id'"; mysql_query($sql); Would increment the column count in the table table by 1. Then you could just retrieve that value.

mazzzzz

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.