PDA

View Full Version : Total Thread Views Counting Wrong


Boofo
12-21-2002, 09:22 PM
Can anyone please help me figure out why the $totalviews always add 1 or 2 to the thread view count whenever someone views a thread? It should only be adding 1 for each view but it is adding between 2 and 3 for every thread view, for some reason.

$countthreads=$DB_site->query_first('SELECT count(*) AS threads, SUM(views) AS views FROM thread');
$totalthreads=number_format($countthreads['threads']);
$totalviews=number_format($countthreads['views']);

Xenon
12-21-2002, 09:27 PM
i'd say looking into showthread.php would help you more :)

Boofo
12-21-2002, 09:30 PM
Any idea where?

Xenon
12-21-2002, 09:39 PM
search for the term views=views+1, it should appear just twice
if it appearse moretimes, theres the problem.
if it's there just twice everything is ok.

rembember whnever you refresh a page or go to anotherpage of the thread the views increses also :)

Boofo
12-21-2002, 10:07 PM
Well it only appears in there twice in this section of code:

if ($noshutdownfunc) {
$DB_site->query("UPDATE thread SET views=views+1 WHERE threadid='$threadid'");
} else {
$shutdownqueries[]="UPDATE LOW_PRIORITY thread SET views=views+1 WHERE threadid='$threadid'";
}

if ($bbuserinfo[cookieuser]) {
set_bbarraycookie('threadview', $threadid, time());
}

I thought it might be Velocd's similar threads hack but I took that code out to test it and it did the same thing. Any other ideas, my man? :)

Chris M
12-21-2002, 10:10 PM
Here is the block of code (not sure if it the same as Boofo's):

if ($bbuserinfo['userid']!=0) {
if ($noshutdownfunc) {
$DB_site->query("UPDATE user SET views=views+1 WHERE userid='$bbuserinfo[userid]'");
} else {
$shutdownqueries[]="UPDATE LOW_PRIORITY user SET views=views+1 WHERE userid='$bbuserinfo[userid]'";
}
}

if ($noshutdownfunc) {
$DB_site->query("UPDATE thread SET views=views+1 WHERE threadid='$threadid'");
} else {
$shutdownqueries[]="UPDATE LOW_PRIORITY thread SET views=views+1 WHERE threadid='$threadid'";
}

:(

Satan

Chris M
12-21-2002, 10:13 PM
^^Hmmm...

It looks like I have 2 blocks of code doing almost the same thing:(

Satan

Xenon
12-21-2002, 10:13 PM
Chris: well on block to much :)
delete the last if block and it's correct

@Boofo: Well then everything works correct, maybe you are just a bit paranoid ;)

Chris M
12-21-2002, 10:21 PM
Hmmm...

Both blocks have slightly different info though...

The last block matches Boofo's, even down to the next lines being:

if ($bbuserinfo[cookieuser]) {
set_bbarraycookie('threadview', $threadid, time());
}

I can't figure out why the top one is there? Is it safe to delete it?:)

Satan

Boofo
12-21-2002, 10:22 PM
Really, I'm not paranoid (shhh...did you hear that? I told you they were after me!) Since I am one of one users that even visits my board, I viewed a thread and went straight back to the forumhome and the number really was 3 higher than when I went to view the thread. How can that be possible? I'm not doubting you, Stefan, I'm just baffled on this is all. :)

Xenon
12-21-2002, 10:27 PM
Chris: the first block just counts views of registred users, the last one counts every view.
you have to decide which one to delete :)

yes it is save :)

@Boofo: hmm, normally it's not possible :)
give me the url of your board so i can have a closer look :)

Boofo
12-21-2002, 10:41 PM
Thanks, Stefan. :)

The URL isset (a little php talk for you there. :)):

http://www.bearfacts2.com

and bring a snow shovel. :)

Chris M
12-22-2002, 11:08 AM
Ah I see;)

I think I'll keep both:D

Satan

Xenon
12-22-2002, 01:07 PM
Chris, then everytime a rigistred users views a thread, it'll count twice ;)

@boofo: i'll recheck it again later, your site is too slow, can't get into the forum now...

Xenon
12-22-2002, 01:55 PM
boofo: i think something works wrong on your board
i can just go to your board if i disable anything (increase the security issues to a maximum)....

ok, but i saw the bug myself...
weird. try to upload an unhacked showthread.php, is the bug still there?
try to revert the showthread templates (backup first ;)). Still buggy?
Have you installed any hacks which has to do with views? (maybe from vbt.com?)