p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

asp_databases thread: Re: paging thru recordsets


Message #1 by "jigs gandhi" <newsgroup@h...> on Fri, 1 Dec 2000 09:54:31 +0530
This is a multi-part message in MIME format.



------=_NextPart_000_0376_01C05B7C.B3884B20

Content-Type: text/plain;

	charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable



hi,



 curpage=3Drequest("curpage")

 set rs=3Dserver.CreateObject("adodb.recordset")

 rs.PageSize=3D10

 rs.Open sql,conn, 3

 if not rs.eof then

      rs.AbsolutePage=3Dcurpage



you can use the pageing method recordset to directly jump to a specific 

page. keep the pagesize equal to what no of records you want to show per 

page.





jigs

  ----- Original Message -----

  From: spencer

  To: ASP Databases

  Sent: Thursday, November 30, 2000 9:11 PM

  Subject: [asp_databases] paging thru recordsets





     this is my code for a search engine on a car site im implementing 

does

  anyone know how i can add code to show only 10 records from 300 per 

page

  then page thru to 300 like most of the search engies ie showing 10 

records

  from 300 click to show 11 to 20 etc

  Dim strcarname

     strcarname =3D Trim(Request("carname"))



     Dim strSQL

     strSQL =3D "SELECT car_desc,car_import FROM car WHERE car_desc LIKE 

'" &_

            strcarname & "%' ORDER BY car_desc"



     Dim objRS

     set objRS =3DServer.CreateObject("ADODB.Recordset")

     objRS.Open strSQL, objConn



     If objRS.EOF then

        Response.Write "There are no cars that match that keyword " & _

                        UCase(strcarname)



     Else

          Response.Write "Your car results " &_

                         UCase(strcarname) & ";<br>"%></font></td>

         

      <td bgcolor=3D"#576685"> <font color=3D"#FFFFFF">Our Price <%  Do 

while not objRS.EOF

          Response.Write "<TR><TD>" & objRS("car_desc")&"</TD>"



          Response.Write "<TD>" & FormatCurrency 

(objRS("car_import"))&"</TD></TR>"

       

            objRS.MoveNext

          Loop

         End If



      objRS.close

      set objRS =3D Nothing



     Set objConn =3D Nothing

  %>



  ---

  FREE SOFTWARE DEVELOPMENT CODE, CONTENT, AND

  INSIGHTS IN YOUR INBOX!

  Get the latest and best C++, Visual C++, Java, Visual Basic, and XML 

tips, tools, and

  developments from the experts.  Sign up for one or more of EarthWeb?s

  FREE IT newsletters at http://www.earthweb.com today! 




$subst('Email.Unsub')










Message #2 by "0 0" <solopress_@h...> on Fri, 01 Dec 2000 11:18:27 -0000
thanks guys !!!!!

Message #3 by "0 0" <solopress_@h...> on Mon, 04 Dec 2000 12:40:14 -0000
im getting a runtime error on this part of the code

Else

    objRS.AbsolutePage = 1

    page_idx = 1









' start of full code



>Dim strcarname

   strcarname = Trim(Request("carname"))



   Dim page_idx

page_idx = (Request.Form( "p_idx"&""))

   Dim page_size

page_size = 10

   Dim strSQL

   strSQL = "SELECT car_desc,car_import FROM car WHERE car_desc LIKE '" &_

          strcarname & "%' ORDER BY car_desc"



   Dim objRS

   set objRS =Server.CreateObject("ADODB.Recordset")

   objRS.Open strSQL, objConn



  objRS.Pagesize = page_size

'telling the server that if there are a large number of records then create 

another results page

  Dim p_count

p_count = objRS.PageCount

if isNumeric(page_idx) and page_idx>0 then



   objRS.AbsolutePage = page_idx

Else

    objRS.AbsolutePage = 1

    page_idx = 1

End if

   If objRS.EOF then

      Response.Write "There are no cars that match that keyword " & _

                      UCase(strcarname)



   Else

        Response.Write "Your car results " &_

                       UCase(strcarname) & ";<br>"%></font></td>

    <td bgcolor="#FFFFFF"> <font color="#000000">Our Price <%  Do while not 

objRS.EOF

        Response.Write "<TR><TD>" & objRS("car_desc")&"</TD>"



        Response.Write "<TD>" & FormatCurrency 

(objRS("car_import"))&"</TD></TR>"



          objRS.MoveNext

        Loop

       End If



    objRS.close

    set objRS = Nothing



   Set objConn = Nothing

%> </font></td>

  </tr>

</table>

<script language="JavaScript">



function initialise_page() {

//should be called when from the onload event of the body



document.all.p_idx.value = "<%=page_idx%>"

}

function next_page(){



document.all.p_idx.value = <%=page_idx%>+1

document.forms.nav_form.submit()

}

function prev_Page() {



       document.all.p_idx.value = <%=page_idx%>-1

       document.forms.nav_form.submit()

}

--/>

</script>

<%

if page_idx>1 then

%>

<p id ="back_text" onclick="prev_page()">Click for previous 

<%=page_size%></p>

<%

end if

if page_idx <objRS.PageCount then

%>

<p id="next_text" onclick="next_page()">Click for next <%=page_size%></p>

<%

end if

%>

<form id="nav_form" method="post" action="results .asp">

      <input type="hidden" id="p_idx" value="0">

</form>


  Return to Index