CGI Forms and "Next 20 Results" button.

I have a Meta Search which returns 100 results.
I put it in a hash with URL being the key. It's a hash of hash's.

I could easily just show all 100 results on one page.
I just print out the hash.
How do I use a "Next 20 Results" button on a CGI Form?

I've tried passing an array and even a reference to array
but it always returns just the first thing on the list. I was thinking about passing a LOT OF DATA , the whole 100 results, back to the
Also, in CGI web programming you have to reload the page every time a button is pressed!

Anyways, my question is this:
How do I make a "Next 20 Results" button if:
a) I can't write to disk (200 users x 100 results, every 5 minutes. No).
b) I have to reload the Form because they pressed a button.
c) I don't want to have to do the Search "AGAIN" everytime they
press a button. I have no way of asking each search engine which
results I want (like 10-20, 30-40, ect....only how many right now).

I'm stumped.......

P.S. I just want the user to be able to see results 20 at a time (out
of the 100 I have for them).  How hard could this be!
Who is Participating?

Improve company productivity with a Business Account.Sign Up

cadabraConnect With a Mentor Commented:
Another option could be to generate HTML pages with the results of the query, and do a redirect to the first result page.

Then the user could navigate between the pre-generated result pages (which contain navigational links between themselves and others as neccessary).

Of course in this approach, you would need to do periodical cleanup of the outdated generated pages.

You can do this using by running a cleanup script via a cron job (in unix), or in the scheduler (NT).
right then

your script returns 100 results. send the first ten and under them put a link with the href pointing to the script that was just called but this time pass a ?start_at=10. this will tell the script to go past the first ten (which the user has already seen) and display the next ten at the bottom of this ten do a link with a strat_at=20 and so on



$start_at = 0
if($query->param('start_at') ne "")
       $start_at = $query->param('start_at')

get you results either database etc

      do nothing,, just move through the results not dislaying them
now you pointer to your current result will point at start_at (you may be able to go straight there ??)
    diplay this ten
if($start_at + 10 < max_results)

using this method you could easily do a back button. if you results are a product of what the user enters in say a search box then this search value will have to be passed in the naviagtion links. for this to work smothly you must really get results in the same order i.e if i was to query a database with "select * from table orderby id" i know that my results will always be in the same order,, unless of course a record was added etc.

this will involve you doing the search each time though .. but i think its your only solution to the problem  

"I could easily just show all 100 results on one page.  I just print out the hash. "

is there a particular reason (reduced download speed or better user experience) that you dont want to show all the 100 but split them in sets of 20??

if your reason is the former then you might have to go for a caching solution, which would cache your search results and serve them 20 at a time.

However, if your reason is the later and you are not too much worried about the download speed, there is a very simple solution which meets all your requirements.

here it is...
lets say your search engine has returned 100 results.
you print the 1st 20 on the browser. the remaining 80 are stored as hidden form elements. Also hidden are the starting # of the next set of results and the no of results to be displayed.

when the user goes to the next page the previous 20 (1-20) are hidden and the hidden results 21 -40 are shown. 41 to 100 are still hidden. The start variable changed to 41 and the no of results changed to 20.

you can keep on doing this till the user reaches the end of the document.

In fact, by using this approach you can give the user facility to jump to certain pages only so if you have 5 pages of 20 results each the user can choose to see any page.

this can happen because at ANY point of time all the results are with the user. its just that they can only "see" the selected 20 at a time.

NOTE: this approach would work well with 100-150 results. Also i would suggest that you dont use tables to display the results. Tables are not displayed till the entire set of tags (from <table> to </table>) are read. so in the meanwhile it appears,  to the user, as if your search is slow.
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

jgoreAuthor Commented:
All three answers would probably work but they have major drawbacks.
1) Redoing the search - too much time.
2) Putting all data in Hidden Fields - to much data passed to user with slower download speeds. Besides,
user could see this if he views source.
3) Writing files which would take a lot of time and resources from computer.

Are all of you sure I can't pass a big array back to my
script?  Why doesn't that work? I did try but only got first element. Even if it was a reference!

the whole problem with CGI is that the variable values are only available during a session. In this case a session would be the user requesting for info, the info coming to your script, the script searching for the details and returning the results.

after this all your variables are lost, unless you use other techiniques (caching etc..). so even if you pass the ref to a variable back to your program, there is no guarantee that you will still find the variable values at that memory location.

i think that eventually you will have to take one of the options that has been suggested here, unless you go for an advanced system/search engine.
jgoreAuthor Commented:
I thank all of you!  Everyone had a good answer.
I wish I could give everyone  the 200 points!

I guess I'll try a method that writes a file. I'll put all
100 results in it and then just send the filename
and which 20 results to show.
This way it's just like sending the whole array back to the script only I'm using disk cache instead of memory.
Or, like Cadabra says: just set up temp html pages
with results.

Hmm....perhaps I could set up a ram disk and have my cake and eat it too! I would still need a cleanup function though.
The life of JAPH is never easy  ;-)

Thanks again everyone!
Nice twist with the ramdisk ... :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.