[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

search script with next/previous button

Hi,

i'm trying to make a search script that searches a database and displays the results but only 10 at a time. If the search returns 200 results I want it to display 10 and then have a next/previous button so that you can view entries before and after...

Is there some code availabel for this? Suppose All my results are in an array called @results could someone please make some code that does the above....

my guess is that it would need to figure out  the total amount of results, figure out which results are being viewed so that it can determine what the next ones should be.
obviously if you are on the first page you will not need a previous button and if you are on the last page you will not need a next button....

Any help would be very much appreciiated i have been trying for ages to work it out.
0
intaman
Asked:
intaman
  • 3
  • 2
1 Solution
 
alamoCommented:
Is your query the type of query that if you run it again when the user presses "Next", you will get the exact same results in the exact same order?

If this is true, the script isn't very tricky at all. If however you can only run the query once then it's more work since you need to save the original results and read them back later. And you need to "clean up" saved copies of old queries.

Which is it?
0
 
intamanAuthor Commented:
Hi,

Yes it is the type of script that will return the same results each time....
But i'm still finding it an impossible task :o(

Thanks

0
 
b2piCommented:
Is this on a local machine, or is this a cgi script that you want?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
intamanAuthor Commented:
Well both really... I want a cgi script (at least the general code to give me an idea that I could modify myself) to use on a local machine....


0
 
b2piCommented:
OK... Here's a rough outline (it's easier to do without the cgi, though) :

Rather than considering a page of displayed records, consider instead a page of records beginning with a particular index.  If the index is not present, consider it to be 0.

Then, you'll have a next button, which simply increments the index by, say 10, and a previous button, which decrements the index by 10.

Each time a post request is made, you'll perform the search , skip the number of records specified by the index, and finally display the appropriate records.

By the way, if this were simply a local process, on the first search, you'd select only the keys for all of the records into an array, and then, using the key, select the data for the first 10 records, using the appropriate keys.  On subsequent searches, you'd already know the keys for the relevant data, and you wouldn't need to re-search the entire data set.
0
 
b2piCommented:
Did you get anywhere with this?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now