Print Page | Close Window

Scratching my head.... +2?

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=6856
Printed Date: 31 March 2026 at 1:54pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Scratching my head.... +2?
Posted By: Gullanian
Subject: Scratching my head.... +2?
Date Posted: 30 October 2003 at 5:38pm

Ok heres my stats code.  Ive been scratching my head over this for weeks.  Why does it add two to the total page views count?  If anyone could solve this id be grateful!


strReferer = Request.servervariables("HTTP_REFERER")

statCurrYear = year(now())

statCurrMonth = month(now())

statCurrDay = day(now())

statCurrHour = hour(now())

'Do statistics

strSQL = "SELECT * from tblStats WHERE statYear = " & statCurrYear & " AND statMonth = " & statCurrMonth & " AND statDay = " & statCurrDay & " AND statHour = " & statCurrHour

rsCommon.open strSQL, adoCon

'Create if none exist

If rsCommon.eof or rsCommon.bof then

rsCommon.close

strSQL = "INSERT INTO tblStats (statYear,statMonth,StatDay,StatHour,sessions,pageViews) VALUES (" & statCurrYear & "," & statCurrMonth & "," & statCurrDay & "," & statCurrHour & ",0,0)"

rsCommon.open strSQL, adoCon

else

rsCommon.close

end if

'CURRENT HOUR SESSIONS/PAGE VIEWS

strSQL = "UPDATE tblStats SET pageViews = pageViews+1 WHERE statYear = " & statCurrYear & " AND statMonth = " & statCurrMonth & " AND statDay = " & statCurrDay & " AND statHour = " & statCurrHour

rsCommon.open strSQL, adoCon

If isEmpty(Session("blnCounterSet")) = True Then

strSQL = "UPDATE tblStats SET sessions=sessions+1 WHERE statYear = " & statCurrYear & " AND statMonth = " & statCurrMonth & " AND statDay = " & statCurrDay & " AND statHour = " & statCurrHour

rsCommon.open strSQL, adoCon

end if

'TOTAL SESSIONS COUNT

If isEmpty(Session("blnCounterSet")) = True Then

strSQL = "UPDATE tblConfiguration SET sessions = sessions + 1"

rscommon.open strSQL, adoCon

'TOTAL PAGE VIEWS COUNT

strSQL = "UPDATE tblConfiguration SET pageviews = pageviews + 1"

rscommon.open strSQL, adoCon

Session("blnCounterSet") = True

'If user is logged in award them a drumpoint

If lngLoggedInUserID <> 2 then

strSQL = "UPDATE tblAuthor set drum_points = drum_points + 1 WHERE author_ID = " & lngLoggedInUserID

rsCommon.open strSQL, adocon

end if

else

'TOTAL PAGE VIEWS COUNT

strSQL = "UPDATE tblConfiguration SET pageviews = pageviews + 1"

rscommon.open strSQL, adoCon

End if

If instr(strReferer,"drum-world.com") = 0 and strReferer <> "" and isnull(strReferer) = False then

strSQL = "SELECT * From tblRefer WHERE URL = '" & strReferer & "'"

rscommon.open strSQL, adoCon

If rscommon.eof or rscommon.bof then

rscommon.close

strSQL = "INSERT into tblRefer (URL,visits) VALUES ('" & strReferer & "',1)"

rsCommon.open strSQL, adoCon

else

rscommon.close

strSQL = "UPDATE tblRefer SET visits = visits + 1 WHERE URL = '" & strReferer & "'"

rsCommon.open strSQL,adocon

end if

end if


I know theres not another file adding to the counter because when I cut this code out it doesnt add anything to the counters.

Any help is appreciated!




Replies:
Posted By: fernan82
Date Posted: 30 October 2003 at 10:37pm
Try this:


If isEmpty(Session("blnCounterSet")) = True Then

strSQL = "UPDATE tblConfiguration SET sessions = sessions + 1"

rscommon.open strSQL, adoCon

Session("blnCounterSet") = True

'If user is logged in award them a drumpoint
If lngLoggedInUserID <> 2 then

     strSQL = "UPDATE tblAuthor set drum_points = drum_points + 1 WHERE author_ID = " & lngLoggedInUserID

     rsCommon.open strSQL, adocon

end if

End If

'TOTAL PAGE VIEWS COUNT

strSQL = "UPDATE tblConfiguration SET pageviews = pageviews + 1"

rscommon.open strSQL, adoCon



My guess is that something is getting screwed and both are getting executed but that way you'll only have it once... I don't think that's the problem though but still you don't need the same code twice...

I think you're including that code on the forum's common.asp or something like that, if so it's gonna get executed twice for some page and probably even three for some as everytime you're redirected to another page the common.asp is loaded again, try including it on header.asp or the footer...

Also I would use .Execute to run all those UPDATE and INSERT, like adoCon.Execute(strSQL), probably that won't make a difference though it's just me I'm used to that... :-)

-------------
FeRnAN
http://www.danasoft.com/">



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net