PDA

View Full Version : Continuing query results on Next Page


zensasha
07-16-2003, 09:18 PM
Greetings! I am having problems carrying the results of a SQL query to the next page... I can go to the next page, but what I get is a display of records beginning with the first entry into the database on. Can someone help me with how to carry the results of my query over to the next page? I have posted the code I am currently using. Any help would be greatly appreciated!
Thanks a million!

<%
// *** Move To Record: set the strings for the first, last, next, and previous links

var MM_moveFirst="",MM_moveLast="",MM_moveNext="",MM_movePrev="";
var MM_keepMove = MM_keepBoth; // keep both Form and URL parameters for moves
var MM_moveParam = "index";

// if the page has a repeated region, remove 'offset' from the maintained parameters
if (MM_size > 1) {
MM_moveParam = "offset";
if (MM_keepMove.length > 0) {
params = MM_keepMove.split("&");
MM_keepMove = "";
for (var i=0; i < params.length; i++) {
var nextItem = params[i].substring(0,params[i].indexOf("="));
if (nextItem.toLowerCase() != MM_moveParam) {
MM_keepMove += "&" + params[i];
}
}
if (MM_keepMove.length > 0) MM_keepMove = MM_keepMove.substring(1);
}
}

// set the strings for the move to links
if (MM_keepMove.length > 0) MM_keepMove += "&";
var urlStr = Request.ServerVariables("URL") + "?" + MM_keepMove + MM_moveParam + "=";
MM_moveFirst = urlStr + "0";
MM_moveLast = urlStr + "-1";
MM_moveNext = urlStr + (MM_offset + MM_size);
MM_movePrev = urlStr + Math.max(MM_offset - MM_size,0);
%>

raf
07-16-2003, 09:34 PM
Welcome here.

I don't use jscript (i assume your code is jscript)

I'm also not sure what you mean by

Can someone help me with how to carry the results of my query over to the next page?


You could run the selectquery again on the next page, or store the recordset in an array (session variabel) or as hidden formfields. But like i said, i'm not sure what you're trying to do. Can you explain whatyou try to achieve ?

zensasha
07-16-2003, 09:43 PM
thanks for helping... The page I'm working on shows the results of a search in the database (in this case, by first name). I have specified for a page to show 10 results so if I have more than 10 matches to the search criteria, I need for the user to be able to click the "Next Page" link and for the next 10 matches to show up.

I'm working with Dreamweaver, but writing some of my own JavaScript. I'm sort of a novice at this, so these more complicated functions are really frustrating. I hope I have clarified. Thanks again.

Roy Sinclair
07-16-2003, 10:04 PM
Did a quick search on the forum here and found the following link:

http://www.source4developers.com/asp/paging.asp

raf
07-16-2003, 10:16 PM
Ha. So you're talking about recordset paging.
What you need is the offset for your next recordset. (on the first page, the ofset = 1, on the second it's 11, ...)
Normally this ofset is appended to the querystring, or computed based on the pagenumber, which is appended to the querystring.
Like(vb script)

response.write("<a href=page.asp?ofset=" & ofset & "'>Next</a>")

the ofset variabel is incremented inside the loop that prints the records.

There are other alternatives:
- storing the complete recordset in an array and use clientsided javascrip for the paging
- storing it in an XML-dataisland (IE only) and the move through the recordset with the xml methods

If you run a search here or on google for recordset paging , you'll find plenty of info, tutorials and code
<edit> posts crossed (watching TV inbetween)</edit>