SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    News 'Read Count'

    Hi,

    I have created a simple php/mysql cms, which allows me to add in news, edit, etc and I then can parse the news items to a newsitem.php?id=1, etc.

    What I would like to do, is add the item "count" to the news database, which basically counts how many "hits/views" the individual news items get. I will then display this on the news item as "This article has been read xxx times".

    If someone could help me with the code that would be required, which I assume needs to be in the newsitem.php file, in the head or something?

    Thanks in advance.

  2. #2
    SitePoint Evangelist Waffles's Avatar
    Join Date
    Nov 2005
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simple

    Add a new field to your news table - "views" or "hits"..

    then do this sql when you select the article to view.

    PHP Code:
    <?

    $hits 
    mysql_query("UPDATE news SET hits = hits+1 WHERE id = '".$_GET['id']."'");

    ?>
    then to view this...when you display the actual article:

    PHP Code:
    <?

    echo 'This has been viewed '$r['hits'].' times!';

    ?>

  3. #3
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks so much for that.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •