Solved

CGI Forms and "Next 20 Results" button.

Posted on 2000-03-16
7
340 Views
Last Modified: 2010-03-05
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
script.
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!
0
Comment
Question by:jgore
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 10

Expert Comment

by:makerp
Comment Utility
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

pseudo-code/perl

cgi...

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

get you results either database etc

form($i=0;$i<=$start_at;$i++)
{
      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 ??)
for($i=0;$i<=10;$i++)
{
    diplay this ten
}
if($start_at + 10 < max_results)
{
    print("<A HREF=this_script.pl?start_at="$start_at+10)
}

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  
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility

"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.
0
 
LVL 2

Accepted Solution

by:
cadabra earned 200 total points
Comment Utility
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).
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:jgore
Comment Utility
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!

Hmmm..........
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
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.
0
 

Author Comment

by:jgore
Comment Utility
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!
0
 
LVL 2

Expert Comment

by:cadabra
Comment Utility
Nice twist with the ramdisk ... :)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
perl exit code 2 243
Perl strange behaviour 5 63
perl split by | 2 80
How to strip .csv from file name 9 75
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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 (http://dilbert.com/strips/comic/2007-08…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now