Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 05-10-2005, 06:02 AM Php counter ...
Novice Talker

Posts: 14
Trades: 0
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
perik is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-10-2005, 11:33 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
I use this code. It only records unique pageviews and not a page refresh

The MySQL table has two columns, page = pagename & count = number of unique views. call hitcount() before any headers are sent out or if you want to show the count on the page use $var = hitcount()


PHP Code:
<?php
session_start
();

function 
hitcount($page) {
$page =  "'" substr($page,0) . "'" ;
if (!isset(
$_SESSION[$page])) {
    
$_SESSION[$page] = true;
$db mysql_connect("server""username""password");
mysql_select_db("database"$db);
$sql ="SELECT * FROM table WHERE page=$page";
$result mysql_query($sql);
$dbrow mysql_fetch_array($result);
//$dbrow[1] is pagename ($page) $dbrow[2] is page views

if (is_null($dbrow[2])) {
$sql "INSERT INTO table (page,count) VALUES ($page,1)";
} else {
$dbrow[2] = $dbrow[2] + 1;
 
$sql "UPDATE table SET count='$dbrow[2]' WHERE page= $page";
}
//echo $sql;
$result mysql_query($sql);
$count $dbrow[2];
mysql_close($db);
return 
$count;
}
}

?>
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-10-2005, 12:55 PM
Novice Talker

Posts: 14
Trades: 0
Does it display the counting on each article in the database for example

article.1 15 views, article.2 4 views etc.
perik is offline
Reply With Quote
View Public Profile
 
Old 05-10-2005, 01:46 PM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It will store whatever you send as the parameter to the function as the pagename. So if you want the pagename to be "fred", Call the function as
PHP Code:
$var hitcount("fred"
and it will return with the pageview count for "fred".
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Php counter ...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33062 seconds with 12 queries