Solved

search script with next/previous button

Posted on 1998-07-05
6
176 Views
Last Modified: 2010-03-05
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
Comment
Question by:intaman
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

by:alamo
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?
0
 

Author Comment

by:intaman
ID: 1208281
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
 
LVL 5

Expert Comment

by:b2pi
ID: 1208282
Is this on a local machine, or is this a cgi script that you want?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:intaman
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....


0
 
LVL 5

Accepted Solution

by:
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.
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1208285
Did you get anywhere with this?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hard perl script 16 161
Can someone please explain what is happening with the declaration of the array @diff? 3 87
add a syntax to a csv file 8 99
Perl modules on linux ec2 3 123
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

679 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