Gossamer Forum
Home : General : Perl Programming :

Search another database from results

Quote Reply
Search another database from results
Need help using some code given in DBMan forum. The original question was:

Topic: Searching different database from results

A user searches database "A" and the results are displayed. I would like to create a link that searches database "B" with the same criteria that was just used to search database "A".

--------------------------

The solution Alex posted was:

my $new_query = $ENV{'QUERY_STRING'};
($new_query =~ s/db=([^&]*?)/db=B/) or ($new_query = $new_query . "&db=B");

Then when linking:

<a href="$db_script_url?$new_query">Search B</a>

What's happening is we are retrieving the previous search from QUERY_STRING environment
variable, then replacing db=old database with db=new datbase, and printing it out again.
You don't need to escape anything as the contents of QUERY_STRING are already still escaped.

----------------------

This isn't working for me?

I'm starting the search within news.db and using the code to below to perform the same search in news2.db

Using:

my $new_query = $ENV{'QUERY_STRING'};
($new_query =~ s/db=([^&]*?)/db=news2/) or ($new_query = $new_query . "&db=news2");

What being returned in the url is:

news.cgi?db=news2news&uid=default&sb=1&so=descend&view_records=1&advanced=1&ID=&Title=&Text=&Category=---&Ailment=ADD%2FADHD&OAilment=&srchwrds=&IssueNo=&ArticleDate-gt=&view_records=View+Records

notice for the db= it has both the old db filename and the new combined rather than replacing the original with the 2nd database (news2) to search within.

Does anyone know how to fix this? It doesn't seem to be stripping the original db filename before creating the link to search within the second database.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Search another database from results In reply to
Watts provided a solution that works:

my $new_query = $ENV{'QUERY_STRING'};
($new_query =~ s/db=news/db=news2/) or ($new_query = $new_query . "&db=news2");

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/