Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limit returned records per page 2

Status
Not open for further replies.

streborr

IS-IT--Management
Jan 16, 2002
98
How do I limit the amount of records returned per page and allow the user to click "prev" or "next" to see other records? Like the pages in this forum.

Thanks for any help?
Rick
 
If isEmpty(Request.QueryString("CurrentPage")) then
CurrentPage = 1
else
CurrentPage = CInt(Request.QueryString("CurrentPage"))
end if

'open the recordset

rsOrderHeaderVague.Pagesize = 5 'Nr. of records on the page
rsOrderHeaderVague.Absolutepage = CInt(CurrentPage)
do until rsOrderHeaderVague.Absolutepage <> Currentpage or rsOrderHeaderVague.eof
'display whatever you need
rsOrderHeaderVague.movenext

'on the buttom of the page you create 2 buttons (Next and Previous). Next will submit the page with CurrentPage = CurrentpAge +1 and Previous will submit the page with CurrentPage = CurrentpAge - 1

If it's not clear I will post this evening the whole code (open recordset, etc...)
Very important the cursor location should be on client!!!!

 
Thanks durug,

I'll give it a shot and posting all the code would really speed things up for me.

thanks again
Rick
 
Yes, but you have to wait like 5 hours until I get home.
 
<%Option explicit
If isempty(Request.Querystring(&quot;PageNumber&quot;)) then
CurrentpAge =1
else
currentPage = Cint(Request.Querystring(&quot;PageNumber&quot;))
ConnectString = &quot;DNS=EMpsDatabase;UserID=ADmin;Password=;&quot;
set rsemps = server.createobject(&quot;adodb.recordset&quot;)
rsemps.cursorlocation = 3 'client side
rsemps.open &quot;tblEmps&quot;,ConnectString,,,2 'tblemps is a table name
rsemps.pagesize = 5 'nr.of records on page
rsemps.absolutepage = currentpage
do until rsemps.absolutepage <> currentpage or rsemps.eof
response.write rsemps(&quot;LastName&quot;)
rsemps.movenext
loop
response.write &quot;select page to view more employee records:&quot;
For i = 1 to rsemps.pagecount
response.write &quot;<a href=&quot;&quot;./adosample.asp?PageNumber=&quot; & i & &quot;&quot;&quot;>&quot; & I & &quot;</a>&quot;
next
%>

It will work for sure! Good Luck and sorry for the delay

Regards,
Durug

 
Thanks Durug!

I have the code in place and after a few adjustments it works. There was one thing I forgot to mention.
The page that contains the code gets populated with data from a query in a &quot;Select Case&quot;(dropdown box). The first group(page1) of information is displayed and the correct number of page links then when you click on the link for page 2(+) no data is displayed.

So, I added this to my Select:
Case else
sqlQuery = request.querystring(&quot;sqlQuery&quot;)

and added the red part:

For i = 1 to rsADO.pagecount
response.write &quot;<a href=&quot;&quot;filter_dist.asp?sqlQuery=&quot; & sqlQuery & &quot;&PageNumber=&quot; & i & &quot;&quot;&quot;>&quot; & i & &quot; </a>&quot;
next

I still only get the first page worth of the recordset and when you click the page links, nothing is displayed except the new page number and all the page links.

Any additional help is extremely appreciated.
Thanks,
Rick
 
Can you post the whole page. I will try to figure out what is going on?

What do you mean by &quot;extremely appreciated.&quot; :)))

Regards,
Durug
 
&quot;extremely appreciated&quot; = less money spent on aspirin:)
Thanks Durug

<%@ Language=VBScript %>

<html>
<head>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;>
<title>Distributor Administrator</title>
<basefont face=&quot;arial&quot;>
<style type=&quot;text/css&quot;>
a { text-decoration: none }
</style>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!-- hide
function openWin1() {
myWin= open(&quot;print_dist.asp&quot;, &quot;displayWindow&quot;,
&quot;status=no,toolbar=no,menubar=no,scrollbars=yes&quot;);
}
// -->
</SCRIPT>
</head>

<body bgcolor=&quot;#FFFFFF&quot; link=&quot;#0000ff&quot; alink=&quot;#ff0000&quot; vlink=&quot;#0000ff&quot; >

<table width=&quot;600&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot;>
<tr>
<td>
<a href=&quot;admin.asp&quot; OnMouseOver=&quot;this.style.color = 'red';&quot; OnMouseOut=&quot;this.style.color = 'blue';&quot;><font size=&quot;-1&quot;> <b>Return to Main Admin Page</b></font></a>
</td>
</tr>
<tr>
<td height=&quot;1&quot; bgcolor=&quot;#000000&quot; colspan=&quot;2&quot; width=&quot;100%&quot;></td>
</tr>
</table>

<table width=&quot;100%&quot; align=&quot;left&quot;>
<tr>
<td width=&quot;100%&quot;>
<b><font size=&quot;+2&quot; color=&quot;#000080&quot;>Distributor Administrator</font></b>
<br>
<font size=&quot;2&quot;>Click on the distributor name to View distributor information.</font>

</td>
</tr>
</table>
<br clear=&quot;all&quot;>
<table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;0&quot;>
<tr>
<td width=&quot;200&quot;>
<form method=&quot;post&quot; action=&quot;filter_dist.asp&quot;>
<font size=&quot;2&quot;>
 <select size=&quot;1&quot; name=&quot;selParent&quot; style=&quot;font-size: 8pt; font-family: Arial&quot;>
<option value=&quot;none&quot;>Select Parent</option>
<option value=&quot;A&quot;>A</option>
<option value=&quot;B&quot;>B</option>
<option value=&quot;C&quot;>C</option>
<option value=&quot;D&quot;>D</option>
<option value=&quot;All&quot;>All</option>
<option value=&quot;nopar&quot;>No Parent</option>
</select>
</font>
<input type=&quot;submit&quot; value=&quot;Go&quot; style=&quot;font-size: 8pt; font-family: Arial&quot;>
</form>
</td>

<form name=&quot;form_list&quot; target=&quot;_self&quot; action=&quot;distadmin.asp&quot; method=&quot;POST&quot; OnClick=&quot;OnClickBtn(this)&quot;>

<td valign=&quot;top&quot;>
<input name=&quot;btnAction&quot; type=&quot;submit&quot; value=&quot; Add &quot; OnClick=&quot;OnClickBtn(this)&quot; style=&quot;font-size: 8pt; font-family: Arial&quot;>
</td>
<td valign=&quot;top&quot;>
<input name=&quot;btnAction&quot; type=&quot;submit&quot; value=&quot; Edit &quot; OnClick=&quot;OnClickBtn(this)&quot; style=&quot;font-size: 8pt; font-family: Arial&quot;>
</td>
<td valign=&quot;top&quot;>
<INPUT TYPE=&quot;BUTTON&quot; VALUE=&quot;Print List&quot; onClick=&quot;openWin1()&quot; style=&quot;font-size: 8pt; font-family: Arial&quot;>
</td>
<td valign=&quot;top&quot;>
<input name=&quot;btnAction&quot; type=&quot;submit&quot; value=&quot; Delete &quot; OnClick=&quot;OnClickBtn(this)&quot; style=&quot;font-size: 8pt; font-family: Arial&quot;>
</td>
</tr>
</table>

<hr color=&quot;#000000&quot;>
<table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;600&quot;>
<tr>
<td>
<table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;600&quot;>
<tr>
<td bgcolor=&quot;#c0c0c0&quot; align=&quot;center&quot; width=&quot;300&quot;><font color=&quot;#000080&quot; size=&quot;2&quot;>Distributor</font></td>
<td bgcolor=&quot;#c0c0c0&quot; align=&quot;center&quot; width=&quot;200&quot;><font color=&quot;#000080&quot; size=&quot;2&quot;>City, ST</font></td>
<td bgcolor=&quot;#c0c0c0&quot; align=&quot;center&quot; width=&quot;100&quot;><font color=&quot;#000080&quot; size=&quot;2&quot;>Parent</font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot;>
<!-- #include file=&quot;adovbs.asp&quot; -->
<%

dim sqlQuery
sqlQuery = Request.form(&quot;selParent&quot;)

Select Case sqlQuery
Case &quot;A&quot;
SQLQuery = &quot;select * from Distributors Where dist_parent= 'A' Order By dist_no&quot;
Case &quot;B&quot;
SQLQuery = &quot;select * from Distributors Where dist_parent= 'B' Order By dist_no&quot;
Case &quot;C&quot;
SQLQuery = &quot;select * from Distributors Where dist_parent= 'C' Order By dist_no&quot;
Case &quot;D&quot;
SQLQuery = &quot;select * from Distributors Where dist_parent= 'D' Order By dist_no&quot;
Case &quot;All&quot;
SQLQuery = &quot;select * from Distributors Order By dist_name&quot;
Case &quot;nopar&quot;
SQLQuery = &quot;select * from Distributors Where (trim(dist_parent)= '') Order By dist_name&quot;
Case &quot;none&quot;
SQLQuery = &quot;select * from Distributors where dist_parent = 'mickey mouse'&quot;
Case else
sqlQuery = query
End Select


dim currentpage, i, pagenumber
If isempty(Request.Querystring(&quot;PageNumber&quot;)) then
CurrentPage =1
else
currentPage = Cint(Request.Querystring(&quot;PageNumber&quot;))
end if
response.write &quot;Page &quot; & currentpage

ConnectionString = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\ ID=;Password=;&quot;
Set rsADO = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rsADO.cursorlocation = 3 'client side
Source = sqlQuery
rsADO.Open Source, ConnectionString

if rsADO.EOF or rsADO.BOF then
%><br>  
<font size=&quot;2&quot; color=&quot;#ff0000&quot;>
<%
response.write &quot;Please choose an item from the list then click 'GO'&quot;
%>
</font>
<%
else

rsADO.pagesize = 10
rsADO.absolutepage = currentpage

rsADO.movefirst
do until rsADO.absolutepage <> currentpage or rsADO.EOF

dim custnum, num, pad
pad = &quot;000000000000&quot;
num = trim(rsADO(&quot;dist_no&quot;))
custnum = pad & num
custnum = right(custnum,6)

%>
<tr>
<td bgcolor=&quot;#eeeeee&quot; width=&quot;300&quot;>
<table cellsapcing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot;>
<tr>
<td valign=&quot;top&quot; align=&quot;right&quot;> <input type=&quot;checkbox&quot; name=&quot;<% =(rsADO(&quot;dist_id&quot;)) %>&quot; value=&quot;ON&quot;>
<font size=&quot;1&quot;><% =custnum %></font>
</td>
<td valign=&quot;top&quot;>
 <a href=&quot;dist_info_wpc.asp?dist_id=<% =(rsADO(&quot;dist_id&quot;)) %>&quot; OnMouseOver=&quot;this.style.color = 'red'; window.status='Click here for more information about <% response.write rsADO(&quot;dist_name&quot;) %> of <% response.write rsADO(&quot;dist_city&quot;) %>, <% response.write rsADO(&quot;dist_state&quot;) %>'; return true&quot; OnMouseOut=&quot;this.style.color = 'blue'; window.status=' '; return true;&quot;><font size=&quot;1&quot;><% =(rsADO(&quot;dist_name&quot;)) %></font></a>
</td>
</tr>
</table>
</td>
<td bgcolor=&quot;#eeeeee&quot; align=&quot;center&quot; width=&quot;200&quot;><font size=&quot;1&quot;><% =(rsADO(&quot;dist_City&quot;)) %>, <% =(rsADO(&quot;dist_State&quot;)) %></font>
</td>
<td bgcolor=&quot;#eeeeee&quot; align=&quot;center&quot; width=&quot;100&quot;><font size=&quot;1&quot;><% =(rsADO(&quot;dist_parent&quot;)) %></font>
</td>
</tr>
<%
rsADO.movenext
loop
response.write &quot;select page to view more distributors:&quot;
For i = 1 to rsADO.pagecount
response.write &quot;<a href=&quot;&quot;filter_dist.asp?sqlQuery=&quot; & request.querystring(&quot;Query&quot;) & &quot;&PageNumber=&quot; & i & &quot;&quot;&quot;>&quot; & i & &quot; </a>&quot;
next

rsADO.close
set rsADO = nothing

end if

%>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
 
I will send you the answer this evening. Is it a rush?
 
Oops, correction for code submitted.


At the bottom of the page it shold read this:

<%
rsADO.movenext
loop
response.write &quot;select page to view more distributors:&quot;
For i = 1 to rsADO.pagecount
response.write &quot;<a href=&quot;&quot;filter_dist.asp?Query=&quot; & sqlQuery & &quot;&PageNumber=&quot; & i & &quot;&quot;&quot;>&quot; & i & &quot; </a>&quot;
next
rsADO.close
set rsADO = nothing
end if
%>

and
Case Else should read:
sqlQuery = request.querystring(&quot;Query&quot;)

sorry,
Rick


 
No rush, Durug.

This is great function to give the end user, for now they will just have to deal with long pages.

Thanks for your help.
Rick
 
I didn't test it yet, just spent some minutes looking over the code (I'm not home yet :))
If you remove the line
rsADO.movefirst
it will work?

Durug
 
It's people like you that make people like me return to places like this!

Thanks, Durug, for your patience and all your help, it's working perfect!
[thumbsup]
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top