Paging records with multiple column table display help

Posted on 2006-06-03
Last Modified: 2012-06-22

I have the code below which I edited to try to make a long story short. :)  The paging works fine when I make it one line per record, but when I try to change the value of the lines:

.PageSize = 2
if counter >= 3 then

it does not do what I think it will do.  If I put
.PageSize = 2
if counter >= 3 then

then it should only display only 2 records although it says there will be 3 records per row.

if I put
.PageSize = 24
if counter >= 2 then

Then I should have 24 records showing in rows of 2 on each page.

However, I cannot see what is wrong with the math here I guess.  It's so very confusing to me.  If anyone cares to take a look I would appreciate it greatly!

    dim thisPage, rowcount, i
    thisPage = Trim(Request("thisPage"))
    if thisPage = "" then thisPage = 1
            Set conn = Server.CreateObject("ADODB.Connection")
            conn.Open xDb_Conn_Str      
            strsqlCFG1 = "SELECT * FROM TABLE"
      Set rstempCFG1 = conn.execute(strsqlCFG1)
      if (rstempCFG1.eof) = true then
          Response.write "Nothing to show you."
Set rstempCFG1 = nothing
set rstempCFG1 = Server.CreateObject("ADODB.Recordset")

    with rstempCFG1
        .CursorType = adOpenStatic
        .PageSize = 3
        .Open "SELECT * FROM TABLE", conn
        .AbsolutePage = cINT(thisPage)

     end with
   rowCount = 0
    while not rstempCFG1.EOF and rowCount < (rstempCFG1.PageSize)
do until rstempCFG1.eof
<td>Data will show here: <%=rstempCFG1("field")
     if counter >= 3 then
            counter = 0
      end if
       counter = counter + 1
       %> <%
            rowCount = rowCount + 1
            if rstempCFG1.eof then
            response.write "</tr>"
        end if
        %> </td>
    Response.Write "<br clear=all>Next Page >"
    for i = 1 to rstempCFG1.PageCount
    %> <a href="page.asp?thisPage=<%=i%>"><%=i%></a> <% next %> <%
end if
end if
set rstempCFG1 = nothing
Question by:JuniorBee
    1 Comment
    LVL 20

    Accepted Solution

    i post my code for paging. this will help u out.


          strDB4Search = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=;"
          strDB4Search = strDB4Search & "DBQ=e:\db\access.mdb"



    <!--#include file="inc/"-->
    <!--#include file="inc/Db.asp"-->
    Dim strDB4Search, objRs, objCon, strSQL
    Const intPageSize = 5
    strQ = Request.QueryString("q")

                            strSQL= "SELECT * FROM TblOverseas WHERE (City LIKE '%%"& strQ & "%%')  AND Price BETWEEN " & Request.QueryString("min") & " AND " & Request.QueryString("max")  & " AND BedRoom = " & Request.QueryString("bed") & " AND BathRoom = " & Request.QueryString("bath")

                            intCurrentPage = Cint(Request.QueryString("cp"))
                            Select Case Request.QueryString("s")
                                  Case "Search"
                                        intCurrentPage = 1
                                  Case "Previous"
                                        intCurrentPage = intCurrentPage - 1
                                  Case "Next"
                                        intCurrentPage = intCurrentPage + 1
                                  Case Else
                                        intCurrentPage = 1
                            End Select

                                  Set objCon = Server.CreateObject ("ADODB.Connection")
                                  objCon.Open strDB4Search
                                  Set objRs = Server.CreateObject ("ADODB.Recordset")
                                  objRs.Open strSQL, objCon,1,3
                                  numOfRecords = objRs.RecordCount

                                  If (objRS.EOF = False) And (objRS.BOF = False) Then
                                        objRS.PageSize = intPageSize
                                  If Not(objRS.EOF) Then objRS.AbsolutePage = intCurrentPage
                                        intTotalPages = objRS.PageCount

                                        formatedPrice = FormatCurrency((objRs("Price")),2)

                                        For intI = 1 To objRS.PageSize

                                              Response.Write "<table border=0>"
                                              Response.Write "<tr>" & vbcrlf
                                              Response.Write "<td height=1>" & objRs("recordshere")
                                              Response.Write "</td>" & vbCrlf
                                              Response.Write "</tr>" & vbcrlf
                                              Response.Write "</table>"

                                              If objRS.EOF Then Exit For
                                              numOfRecords = objRs.RecordCount

                                              Response.Write"<table align=center>"
                                              If intCurrentPage > 1 Then
                                                    Response.Write "<a href='" & Request.ServerVariables("SCRIPT_NAME") & "?q=" & Server.URLEncode(Request.QueryString("q")) & "&s=Previous" & "&cp=" & intCurrentPage &"'>Previous</a>"
                                              End If

                                              If (intCurrentPage > 1) And (intCurrentPage < intTotalPages) Then
                                                    Response.Write "&nbsp;|&nbsp;"
                                              End If

                                              If intCurrentPage <> intTotalPages Then
                                                    Response.Write "<a class='red9B' href='" & Request.ServerVariables("SCRIPT_NAME") & "?q=" & Server.URLEncode(Request.QueryString("q")) & "&s=Next" & "&cp=" & intCurrentPage & "'>Next</a>"
                                              End If


                                              Set objRs = Nothing
                                              Set objCon = Nothing


    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
    I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now