+ Reply to Thread
Results 1 to 6 of 6

Thread: *Counting Views* tutorial

  1. #1
    gptsven is offline x10 Lieutenant gptsven is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    253

    *Counting Views* tutorial

    Introduction
    ah! counting visitors! it's something simple yet hard to do! The following script allows you to count howmany times your article get's read and displays this on the article in a datatable, you can however NOT show the "times read" on your article but it sure is interesting for your visitors!
    How does it work
    It's simple. but not super-simple. you create a table holding an IP,DATE,PARENT_ID and if needed more information, like I did include a type. when the page loads you update the table using a sql query. my query checks if the IP did not request the same article in a time period of 10 minutes. this ensures that the visitor did not hit "back" on accident and eliminates valse countings. did you rly expect a script that just "updates". I like my statistics to be correct so I use this system it still isnt fool proof. but almost...

    why should you use it?
    -
    statistics for yourself.
    - statistics for visitors ( they like it!)

    adding soon
    script that checks if anonymous proxy-server is found. if yes do not update at all.

    the script!
    PHP Code:
    // UPDATEN VAN DE VIEWS INDIEN DE BEZOEKER NIET DE LAATSTE 3 MINUTEN GELEDEN HET ARTIKEL BEZICHTICHT HEEFT
            
    $newquery "SELECT * FROM article_views WHERE date > (NOW()- INTERVAL 10 MINUTE) AND parent_id=$id AND ip='".$_SERVER['REMOTE_ADDR']."'";
            
    $resultzz mysql_query($newquery);
            if (
    mysql_num_rows($resultzz) == 0)
            {
                
    mysql_query("INSERT INTO article_views (ip,date,parent_id,type) VALUES ('$_SERVER[REMOTE_ADDR]',now(),'$id','paid')");
            }
            
    // FETCHEN VAN VIEW-DATA
            // --- FETCHEN VAN TOTAAL AANTAL KEER GELEZEN ---
            
    $newquery "SELECT COUNT(*) AS total FROM article_views WHERE parent_id=$id AND type='paid'";
            
    $view_result mysql_query($newquery);
            
    $viewdata mysql_fetch_assoc($view_result);
            
    $views $viewdata['total']; 
    just echo $viewdata['total'] to print the number of views.

    ENJOY!

    ( I WROTE THIS CODE & TUTORIAL... please give credit to me if you post this somewhere else )

  2. #2
    Fahad Guest

    Re: *Counting Views* tutorial

    In your cPanel you will find awstats, which has much more detailed statistics than this.

  3. #3
    gptsven is offline x10 Lieutenant gptsven is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    253

    Re: *Counting Views* tutorial

    Quote Originally Posted by fahadsadah View Post
    In your cPanel you will find awstats, which has much more detailed statistics than this.
    please shut up if you are just going to say something stupid. this has nothing to do with awstats. this is 100% more flexible.it only is to count article views ok? cause its YOUR CODE you can print tables of data HOW YOU WANT and you can give visitors more information too.

    gosh man

  4. #4
    gptsven is offline x10 Lieutenant gptsven is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    253

    Re: *Counting Views* tutorial

    bumpi

  5. #5
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: *Counting Views* tutorial

    Quote Originally Posted by gptsven View Post
    please shut up if you are just going to say something stupid.
    Chill out and keep it civil. The "shut up" undermines any courtesy of the "please".

    Recommending awstats is hardly stupid. Recommending any existing solution isn't stupid. There are many web analytics applications out there that let you decide how you want to crunch numbers and format reports. Some (you'll find) do what your code does and more. The point is to be aware of what's available, and what they have to offer.

    Quote Originally Posted by gptsven View Post
    bumpi
    Don't be gauche.
    Last edited by misson; 12-27-2009 at 01:52 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  6. #6
    vishal's Avatar
    vishal is offline -::-X10 Guru-::- vishal has a brilliant futurevishal has a brilliant future
    Join Date
    Nov 2009
    Location
    INDIA
    Posts
    5,254

    Smile Re: *Counting Views* tutorial

    ya good tutorial, can u pls put that prints number of views in a FACY way ,imean as we see in some websites as led images or calculator letters.... pls
    Regards ~ Vishal
    Giving Reputation (at bottom of my post ) is the best way to encourage the person who helped you on forums.

+ Reply to Thread

Similar Threads

  1. A HTML + CSS Basic Tutorial
    By Zenax in forum Tutorials
    Replies: 14
    Last Post: 09-02-2011, 01:42 PM
  2. Post a Tutorial and Get Credits
    By Sohail in forum The Marketplace
    Replies: 2
    Last Post: 06-17-2008, 10:27 PM
  3. Cron Tutorial (Crontab Tutorial)
    By sunils in forum Tutorials
    Replies: 3
    Last Post: 06-14-2008, 10:34 PM
  4. Replies: 2
    Last Post: 12-16-2006, 08:59 PM
  5. Network Folder Sharing Tutorial
    By TheJeffsta in forum Computers & Technology
    Replies: 0
    Last Post: 03-31-2006, 02:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers