?
Solved

Paging records with multiple column table display help

Posted on 2006-06-03
1
Medium Priority
?
284 Views
Last Modified: 2012-06-22
Hi,

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."
      Else
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)
    %>
<table>
<tr>
<%
do until rstempCFG1.eof
%>
<td>Data will show here: <%=rstempCFG1("field")
</td>
  <%
     if counter >= 3 then
            counter = 0
      end if
       counter = counter + 1
     rstempCFG1.movenext
       %> <%
            rowCount = rowCount + 1
        loop
            if rstempCFG1.eof then
            response.write "</tr>"
            else
        rstempCFG1.MoveNext
        end if
        %> </td>
</tr>
</table>
<%
wend    
    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
%>
0
Comment
Question by:JuniorBee
1 Comment
 
LVL 20

Accepted Solution

by:
Gawai earned 2000 total points
ID: 16825997
i post my code for paging. this will help u out.

''DB.asp
<%


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


 %>

''paging.asp

<!--#include file="inc/adovbs.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>"

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


                                          Response.Write"<table align=center>"
                                          Response.Write"<tr>"
                                          Response.Write"<td>"
                                          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

                                          Response.Write"</td>"
                                          Response.Write"</tr>"
                                          Response.Write"</table>"





                                          objCon.close
                                          Set objRs = Nothing
                                          Set objCon = Nothing


%>
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

807 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