search script with next/previous button

Posted on 1998-07-05
Last Modified: 2010-03-05

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.
Question by:intaman
  • 3
  • 2

Expert Comment

ID: 1208280
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?

Author Comment

ID: 1208281

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(



Expert Comment

ID: 1208282
Is this on a local machine, or is this a cgi script that you want?
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.


Author Comment

ID: 1208283
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....


Accepted Solution

b2pi earned 340 total points
ID: 1208284
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.

Expert Comment

ID: 1208285
Did you get anywhere with this?

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question