Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Scratching my head.... +2?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Scratching my head.... +2?

 Post Reply Post Reply
Author
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Topic: Scratching my head.... +2?
    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!

Back to Top
fernan82 View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 17 November 2002
Location: United States
Status: Offline
Points: 362
Post Options Post Options   Thanks (0) Thanks(0)   Quote fernan82 Quote  Post ReplyReply Direct Link To This Post 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... :-)

Edited by fernan82
FeRnAN
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.