Where can I find info on dividing query results in

# Thread: Where can I find info on dividing query results in

1. David Brower Guest

## Where can I find info on dividing query results in

I&#039m sure this has been asked a thousand times already but I just can&#039t see to find any information on it: when I run a query on the database I sometimes get a thousand results or so, which is far too much of course. Does anyone know how to show, for example, just 10 records on one page with a link to the next/previous 10 records. I&#039d really appreciate any help on this as I&#039ve spent the weekend raking through books and articles trying to find an answer.<BR> cheers<BR>David Brower, Paisley University, Scotland<BR>

2. Ledy Gamitin Guest

## RE: Where can I find info on dividing query result

You can have 2 ASP pages, one for the first 10 results (let&#039s call it results.asp) and another one for the rest of the results (nextresults.asp). Here&#039s a sample code:<BR><BR>--&#062; results.asp<BR>&#039connect to the db<BR>&#039execute query and put results in a recordset (rs)<BR><BR>if rs.eof then<BR> &#039no results found<BR>else<BR> &#039check the number of rows returned<BR> if rs("cnt") &#062; 10 then <BR> ctr = 1<BR> do while (ctr &#060;= rs("cnt")) and not rs.eof<BR> &#039display result<BR> ctr = ctr + 1<BR> rs.movenext<BR> loop<BR> &#039display Next Results link<BR> &#060;a href="nextresults.asp?ctr=&#060;%=ctr%&#062;&rows= &#060;%=rs("cnt")%&#062;<BR> Next 10 Results<BR> &#060;/a&#062;<BR> rs.close &#039close recordset<BR> else &#039if results &#060;= 10<BR> &#039display results<BR> end if<BR>end if<BR><BR>rs.close<BR>&#039close connection<BR><BR>--&#062;nextresults.asp<BR>&#039connect to db<BR>&#039execute same query<BR><BR>RowCount = Request("rows")<BR>temp = Request("ctr") + 10<BR>if temp &#062; RowCount then<BR> count = 10 - (temp - RowCount)<BR> Response.write("Results " & temp-10+1 & " to " & RowCount)<BR>else<BR> count = temp<BR> Response.write("Results " & count-10+1 & " to " & count)<BR>end if<BR>Response.write(" of " & RowCount)<BR><BR>rs.move(ctr)<BR>do while not rs.eof and count&#060;&#062;ctr<BR> ctr = ctr + 1<BR> &#039display result<BR> rs.movenext<BR>loop<BR><BR>if RowCount &#062; temp then<BR> &#039display next results link<BR> &#060;a href="nextresults.asp?ctr=&#060;%=count%&#062;&row s=&#060;%=RowCount%&#062;"&#062;<BR> Next 10 Results<BR> &#060;/a&#062;<BR>end if<BR><BR>rs.close<BR>&#039close connection<BR><BR>Ledy Gamitin<BR>Calcmenu Phils., Inc.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•