Gossamer Forum
Home : Products : DBMan : Customization :

Searching different database from results

Quote Reply
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".

Basically it's the $ENV{'QUERY_STRING'} but I want to change db=A to db=B

Any help is appreciated
Quote Reply
Re: Searching different database from results In reply to
There may be an easier way to do this, but this is the only way I can think of.

Create your link like

<a href="$db_script_url&db=B&uid=$db_uid&Field1=$in{'Field1'}&Field2=$in{'Field2'}&view_records=1">
Search in database B</a>

Of course, you would replace "Field1" and "Field2" with the names of your fields and would probably have more possible fields to search on. For each one, use

&Field=$in{'Field'}

If there's a chance that any of the $in{'Field'} values will have spaces or any characters other than letters and numbers, you'll need to encode them before you put them in the URL. Add the following just before you print the URL.

Code:
foreach $key (keys %in) {
$in{$key}=~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$in{$key}=~s/\%2F/\//g;
}

Be sure to close off any print qq| statement with a |; before you add this code and start another print qq| statement before you print the URL.

As I say, there's probably an easier way to do it, but this will probably work.


------------------
JPD


[This message has been edited by JPDeni (edited April 03, 1999).]
Quote Reply
Re: Searching different database from results In reply to
JP
Thank you very much, works like a champ. I was missing the code on my solo attempts.
Thanks again for such a quick (and accurate) response.
Earl
Quote Reply
Re: Searching different database from results In reply to
Another way to do it:

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.

Hope this helps,

Alex


[This message has been edited by Alex (edited April 03, 1999).]

[This message has been edited by Alex (edited April 03, 1999).]
Quote Reply
Re: Searching different database from results In reply to
See? I *knew* there was an easier way!! Smile

------------------
JPD





Quote Reply
Re: [JPDeni] Searching different database from results In reply to
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 wiht 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] Searching different database from results In reply to
Could you do something like this?

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

This works for me, but I may not understand all of the implications.
Quote Reply
Re: [Watts] Searching different database from results In reply to
Thanks Watts!!!

That works great!

Unoffical DBMan FAQ

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