CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> CodeChargeStudio.Discussion

 Update counter, times link is clicked

Print topic Send  topic

Author Message
madlobster
Posted: 05/21/2003, 1:07 PM

Has anyone implemented updating a counter that tracks the number of times a
link has been clicked on a site?

I have a series of links that I would like to track the number of times they
are followed. For example, I have a table - link_id, link, link_ctr. I
would like to display a list of the links and update link_ctr by adding 1
each time the link is clicked.

I am doing this to try and create a Top XX list.

Is there another way? Maybe I could write an entry into a table with the
link id and a date/time stamp?

Any suggestions would be greatly appreciated.

Thanks.

DonB
Posted: 05/21/2003, 2:45 PM

This is some code I wrote. It counts the hits. I happened to have in the
Page_BeforeShow event. You wanted a link click, so you'll have to put it
elsewhere.

DonB




Function Page_BeforeShow() 'Page_BeforeShow @1-653D685B

'Custom Code @14-73254650
' -------------------------
'On Error Resume Next
Dim sql
Dim strREFERER
Dim strIP
Dim SessionID

SessionID = Cstr(Session.SessionID) ' Bump the count only for each unique
visit

strREFERER = Request.ServerVariables("HTTP_REFERER")
if strREFERER = "" then strREFERER = "?"

strIP = Request.ServerVariables("REMOTE_ADDR")

if dbconnection1.state = adStateClosed Then dbconnection1.open

' Assume the IP exists, increment the hit counter

The table VistorLog is defined like this:

EntryID AutoNumber
EntryTime Date/Time
IP Text(16)
HTTPreferrer Text(50)
Hits Long Integer
SessionID Text

I detect the IP and keep track of hits from each IP address. I also record
the session ID and only increment the count when the session ID changes
(this is not perfect, as the sessionID can repeat, but I figured it was good
enough.

My CCS connection to Access is named "connection1".

' Try to bump the count if visitor IP is already in the database
sql = "UPDATE VisitorLog SET Hits = Hits + 1, " + _
" EntryTime = '" + cstr(Now()) + "', " + _
" HTTPReferrer = '" + strREFERER + "', " + _
" SessionID = '" + SessionID + "'" + _
" WHERE IP = '" + strIP + "' " + _
" AND (SessionID <> '" + SessionID + "' OR SessionID IS NULL)"

dbconnection1.execute sql

' Do an INSERT, in case the IP does not exist

sql = "INSERT INTO VisitorLog (EntryTime, IP, SessionID, HTTPREFERRER,
Hits) VALUES ('" + _
cstr(Now) + "', '" + _
strIP + "' , '" + _
SessionID + "' , '" + _
strREFERER + "', 1);"
' response.write "<B>" + SQL + "<?/B>"
dbconnection1.execute SQL

' Hit counter: Increment the count for each new visit (i.e., don't
increment on a browser refresh)
Dim MyHits
Dim AllHits
Dim VisitCount

MyHits = CCDLookUp("Hits", "VisitorLog", "IP = '" + strIP + "'",
DBconnection1)
AllHits = CCDLookUp("SUM(Hits)", "VisitorLog", "", DBconnection1)
VisitCOunt = CCDLookUp("COUNT(Hits)", "VisitorLog", "", DBconnection1)

'Display the hits in a label "HitCount" on the main page
HitCount.Value = " - Your visit count: " + Cstr(MyHits) + ". ("
+ Cstr(VisitCount) + " visitors have been here " + Cstr(AllHits) + " times)"

' -------------------------
'End Custom Code

End Function 'Close Page_BeforeShow @1-54C34B28

"madlobster" <pleaseposthere@codechargenews.com> wrote in message
news:bagm9i$rhd$1@news.codecharge.com...
> Has anyone implemented updating a counter that tracks the number of times
a
> link has been clicked on a site?
>
> I have a series of links that I would like to track the number of times
they
> are followed. For example, I have a table - link_id, link, link_ctr. I
> would like to display a list of the links and update link_ctr by adding 1
> each time the link is clicked.
>
> I am doing this to try and create a Top XX list.
>
> Is there another way? Maybe I could write an entry into a table with the
> link id and a date/time stamp?
>
> Any suggestions would be greatly appreciated.
>
> Thanks.
>
>


   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.