Visitor Counter Admin Page

<% 'Dimension variables Dim adoCon 'Database Connection Variable Dim adoRec 'Database Recordset Variable Dim strAccessDB 'Holds the Access Database Name Dim strSQL 'Database query sring Dim intRecordPositionPageNum 'Holds the record position Dim intRecordLoopCounter 'Loop counter for displaying the database records Dim intTotalNumDBEntries 'Holds the total number of records in the database Dim intTotalNumDBPages 'holds the total number of pages in the database Dim intLinkPageNum 'Holds the page number to be linked to Dim strPageName 'Holds the page name of the file with the hit counter Dim lngTotalCounter 'Holds the total vistitor counter Dim dtmTotalCounterDate 'Holds the date the visitor counter is from Dim lngResetCounter 'Holds the visitor count number since reset Dim dtmResetCounterDate 'Holds the date the reset counter was reset Dim blnAllCountersSelected 'Set to true if the user has choosen to select all counters 'Declare constants Const intRecordsPerPage = 10 'Change this number to the amount of database entries to be displayed on each page 'Initalise variables blnAllCountersSelected = False 'If this is the first time the page is displayed then the dayabase record position is set to page 1 If Request.QueryString("PagePosition") = "" Then intRecordPositionPageNum = 1 'Else the page has been displayed before so the database record postion is set to the Record Position number Else intRecordPositionPageNum = CInt(Request.QueryString("PagePosition")) End If 'If the user has choosen to selct all visitor counters then set the variable blnAllCountersSelected to True If Request.QueryString("mode") = "SelectAll" Then blnAllCountersSelected = True 'Initialise the strAccessDB variable with the name of the Access Database strAccessDB = "hit_count" 'Create a connection odject Set adoCon = Server.CreateObject("ADODB.Connection") Set adoRec = Server.CreateObject("ADODB.Recordset") '------------- If you are having problems with the script then try using a diffrent driver or DSN by editing the lines below -------------- 'Database connection info and driver (if this driver does not work then comment it out and use one of the alternative drivers) strCon = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath(strAccessDB) 'Alternative drivers faster than the basic one above 'strCon = "Provider=Microsoft.Jet.OLEDB.3.51; Data Source=" & Server.MapPath(strAccessDB) 'This one is if you convert the database to Access 97 'strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(strAccessDB) 'This one is for Access 2000 'If you wish to use DSN then comment out the driver above and uncomment the line below (DSN is slower than the above drivers) 'strCon = "DSN=forum" 'Place the DSN name after the DSN= '--------------------------------------------------------------------------------------------------------------------------------------------- 'Open a connection to the database adoCon.Open strCon 'Initalise the strSQL variable with an SQL statement to query the database by selecting all tables ordered by the decending date strSQL = "SELECT * FROM tblHitCount " 'Set the cursor type property of the record set to Dynamic so we can navigate through the record set adoRec.CursorType = 3 'Query the database adoRec.Open strSQL, adoCon 'Set the number of records to display on each page by the constant set at the top of the script adoRec.PageSize = intRecordsPerPage 'Get the database record poistion to display from If NOT adoRec.EOF Then adoRec.AbsolutePage = intRecordPositionPageNum 'Count the number of enties in the database intTotalNumDBEntries = CInt(adoRec.RecordCount) 'Count the number of pages there are in the database calculated by the PageSize attribute set above intTotalNumDBPages = CInt(adoRec.PageCount) 'If there are no rcords in the database display an error message If adoRec.EOF Then 'Tell the user there are no records to show Response.Write "There are no records in the database" Response.Write "
Please check back later" Response.End 'Display the datbase records Else 'Display in HTML the total number of pages and total number of records in the database Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & "
" Response.Write vbCrLf & " There are " & intTotalNumDBEntries & " visitor counter entries on " & intTotalNumDBPages & " pages and your are on page number " & intRecordPositionPageNum & "" Response.Write vbCrLf & "
" Response.Write vbCrLf & "
" ' loop through the records in the database and show the infomation ' using a Do While...Loop statement For intRecordLoopCounter = 1 to intRecordsPerPage 'If there are no visitor counter records left to display then exit loop If adoRec.EOF Then Exit For 'Read in the values form the database strPageName = adoRec("Page") lngTotalCounter = CLng(adoRec("Total_Counter")) dtmTotalCounterDate = CDate(adoRec("Total_Date")) lngResetCounter = CLng(adoRec("Reset_Counter")) dtmResetCounterDate = CDate(adoRec("Reset_Date")) 'Display the visitor counters in HTML Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & "
" 'If the user has choosen to select all the counters on the page than make the check box checked If blnAllCountersSelected = True Then 'Display a check box for the hit counter already checked Response.Write vbCrLf & "

" Else 'Dipsplay a check box for the hit counter not already checked Response.Write vbCrLf & "

" End If Response.Write vbCrLf & "
Page Name: " & strPageName & " " Response.Write vbCrLf & "
" Response.Write vbCrLf & " Total visitors:  " & lngTotalCounter & " since " & dtmTotalCounterDate & "
" Response.Write vbCrLf & " Reset visitors: " & lngResetCounter & " since " & dtmResetCounterDate & "
" Response.Write vbCrLf & "
" Response.Write vbCrLf & "
" ' Move to the next record adoRec.MoveNext Next End If %>
Select All Counters
<% 'Display an HTML table with links to the other entries in the database Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & "
" Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & "
" 'If there are more pages to display then add a title to the other pages If intRecordPositionPageNum > 1 or NOT adoRec.EOF Then Response.Write vbCrLf & " Page:  " End If 'If the datbase page number is higher than page 1 then display a back link If intRecordPositionPageNum > 1 Then Response.Write vbCrLf & " << Prev   " End If 'If there are more pages to display then display links to all the pages If intRecordPositionPageNum > 1 or NOT adoRec.EOF Then 'Display a link for each page in the guestbook For intLinkPageNum = 1 to intTotalNumDBPages 'If the page to be linked to is the page displayed then don't make it a hyper-link If intLinkPageNum = intRecordPositionPageNum Then Response.Write vbCrLf & " " & intLinkPageNum Else Response.Write vbCrLf & "  " & intLinkPageNum & "  " End If Next End If 'If it is Not the End of the database entries then display a next link for the next database page If NOT adoRec.EOF then Response.Write vbCrLf & "  Next >>" End If 'Finsh HTML the table Response.Write vbCrLf & "
" Response.Write vbCrLf & "
" 'Reset Sever Objects Set adoCon = Nothing Set adoRec = Nothing %>


Return to the Hit Counter Default Page