*Counting Views* tutorial

gptsven

New Member
Messages
253
Reaction score
5
Points
0
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:
// 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 )
 
F

Fahad

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

gptsven

New Member
Messages
253
Reaction score
5
Points
0
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
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
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.

Don't be gauche.
 
Last edited:

vishal

-::-X10 Guru-::-
Community Support
Messages
5,255
Reaction score
192
Points
63
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
 
Top