<%@ LANGUAGE=VBScript %> <% 'db connection Dim cnnSimple Dim rstSimple Dim strDBPath Dim strSQL 'guestbook vars Dim pageTotal Dim recordTotal Dim pageNow Dim recordCount 'is used 2 times for a different process... Dim recordStart Dim cursorPlace Dim pageLength 'pageLengte is the length of your page, set manually according to your layout pageLength = 3 strDBPath = Server.MapPath("raguestbook.mdb") Set cnnSimple = Server.CreateObject("ADODB.Connection") cnnSimple.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";" strSQL = "SELECT * FROM guestbook ORDER BY userID DESC" Set rstSimple = cnnSimple.Execute(strSQL) 'determine page If Request.QueryString("page") = "" Then pageNow = 1 Else pageNow = CInt(Request.QueryString("page")) End If 'count records, this is the easiest way to do it, and as long as your db doesn't 'have k's of records it's ok to use. Do While Not rstSimple.EOF recordTeller = recordTeller + 1 rstSimple.MoveNext Loop rstSimple.MoveFirst pageTotal = (recordCount / pageLength) If Int(pageTotal) = 0 then pageTotal = 1 If (pageTotal / Int(pageTotal)) <> 1 Then pageTotal = Int(pageTotal) + 1 'display page x of x If pageNow > pageTotal Then pageNow = pageTotal If pageNow < 1 Then pageNow = 1 %> page <%= pageNow %> of <%= pageTotal %>

<% 'page selction If pageNow <> 1 Then %> previous <% End If If pageNow < pageTotal Then %>next <% End If %> <% 'record to start with recordStart = ((pageNu -1) * pageLength) If recordStart = 0 Then recordStart =1 'get the cursor to the right place. Do While cursorPlace < recordStart AND NOT recordStart = 1 rstSimple.MoveNext cursorPlace = cursorPlace + 1 Loop 'Here we go, display the guestbook. I kept the code as simple as possible 'so there's no layout at all... recordCount = 0 Do While recordCount < pageLength And Not rstSimple.EOF %>
<%= rstSimple.Fields("name").Value%> "> <%= rstSimple.Fields("email").Value%> <%= rstSimple.Fields("datum").Value%>
<%= rstSimple.Fields("subject").Value%> <%= rstSimple.Fields("content").Value%>

<% rstSimple.MoveNext recordCount = recordCount + 1 Loop 'pageselection, same as above If pageNow <> 1 Then %>previous |<% end if if pageNow < pageTotal Then %>next<% End If %>
Post a message