<% ' This code writes a page count to a database table named counter: on error resume next myPageName = "HomeNav" ' The page name must be unique Set rs = Server.CreateObject ("ADODB.Recordset") Set rs.ActiveConnection = myConn rs.cursortype = 1 rs.locktype = 3 ' construct a SQL statement to query the database. the pagecount table is called Counter sqlString = "SELECT id, pagename, pagecount, datecreated, datehit" sqlString = sqlString & " FROM counter" ' note: pageName is a text field so myPageName is enclosed in single quotes in the SQL statement sqlString = sqlString & " WHERE PageName = '" & myPageName & "'" rs.Source = sqlString rs.Open rs.movefirst 'if pageName is not currently in Counter, we must add a record for it to Counter if NOT(Err.Number <> 0) then if rs.EOF or rs.BOF then myCount = 1 myDateHit = Now() sqlString = "INSERT INTO counter" sqlString = sqlString & " (pagename, pagecount, datecreated, datehit)" sqlString = sqlString & "SELECT '" & myPageName & "' AS pagename," sqlString = sqlString & " '1' AS pagecount," sqlString = sqlString & " '" & Now() & "' AS datecreated," sqlString = sqlString & " '" & Now() & "' AS datehit;" myConn.Execute sqlString 'if pageName does have a record in Counter, then we shall update it accordingly ' else ' myDateHit = RS("DateHit") ' myNewCount = RS("PageCount") + 1 ' sqlString = "UPDATE counter" ' sqlString = sqlString & " SET PageCount = " & myNewCount & "," ' sqlString = sqlString & "DateHit = '" & Now() & "'" ' sqlString = sqlString & " WHERE ID = " & RS("ID") ' myConn.Execute sqlString ' end if 'else ' Response.Write "There were errors" & vbCr 'end if ' if the recordset is not empty, UPDATE the existing record changing the count and last hit fields ' myCount equals the myCount value from the counter table + 1 ' last hit equals Now() else myDateHit = RS("datehit") myNewCount = RS("pagecount") + 1 sqlString = "UPDATE counter" sqlString = sqlString & " SET pagecount = " & myNewCount & "," sqlString = sqlString & " datehit = '" & Now() & "'" sqlString = sqlString & " WHERE id = " & RS("id") myConn.Execute sqlString end if else response.write "There were errors…" & vbCr end if %>



<%=myNewCount%> Besucher seit: 25.08.2000 <%=formatdatetime(rs("datecreated"),2)%>

<%=myDateHit%>
<% rs.Close myConn.Close %>