search script with next/previous button


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.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

b2piConnect With a Mentor Commented:
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.
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?
intamanAuthor Commented:

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(


Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Is this on a local machine, or is this a cgi script that you want?
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....

Did you get anywhere with this?
All Courses

From novice to tech pro — start learning today.