Gossamer Forum
Home : Products : DBMan : Customization :

num_records with multiple database

Quote Reply
num_records with multiple database
I have two separate databases (not relational) running through one db.cgi using format.pl and two separate *_html.pl files for the differences in record layout. I would like to display the number of records in each database (at the same time) with a call to the subroutine from format.pl (in the "header" section such that both record counts appear on all pages displayed).

How would I do this?

Valerie
http://www.skymax-usa.com
http://www.ad-ink.com
Quote Reply
Re: num_records with multiple database In reply to
You can do one of the following options:

1) Copy the sub num_record routine and call the copied sub sub num_record2.

Then you will have to add another field in your multiple .cfg files called $db_file_name2, $db_file_name3. Then replace $db_file_name in the new sub-routines with $db_file_name2.

2) OR you can use the following conditional statements in the sub num_records:

Code:

if ($in{'db'} eq "name1")
open (DB, "</path/to/cgi-bin/dbman/name1.db") or &cgierr("error in num_records. unable to open database:/path/to/cgi-bin/dbman/name1.db.\nReason: $!");
}
if ($in{'db'} eq "name2")
open (DB, "</path/to/cgi-bin/dbman/name2.db") or &cgierr("error in num_records. unable to open database:/path/to/cgi-bin/dbman/name2.db.\nReason: $!");
}
else {
print "No database selected.";
}


Then replace /path/to/cgi-bin/dbman/name1.db and /path/to/cgi-bin/dbman/name2.db with the COMPLETE ABSOLUTE path to your database files and the exact name of your database files.

You also need to change name1 and name2 to the name of your database files.

Hope this helps.

Regards,


Eliot Lee
Quote Reply
Re: num_records with multiple database In reply to
Eliot,

Thank you!

Assuming the second option, I think I'll need to pass in the name of the database (for each separate call to &num_records) from format.pl, yes? Would this be as simple as:

&num_records ('name1'); where name1= the name of one of the databases and
&num_records ('name2'); where name2= the name of the other?

Again, thank you.


Valerie
http://www.skymax-usa.com
http://www.ad-ink.com
Quote Reply
Re: num_records with multiple database In reply to
Nope...the conditional statements take care of that....

You simply use &num_records.

Regards,

Eliot Lee
Quote Reply
Re: num_records with multiple database In reply to
Hmmm...I'll be calling &num_records twice - one line after the other in format.pl and attaching the word "Resumes" or "Job Openings" after each call with a print statement. And...I just tried this...and the last option prints (no database selected).

Valerie
http://www.skymax-usa.com
http://www.ad-ink.com
Quote Reply
Re: num_records with multiple database In reply to
Well, since you want to print them in the page where both results from the databases appear...you will have to go with the first option...create two subs, then replace $db_file_name with the complete absolute path to your .db file in each of the subs.

Then call the sub with &num_records and &num_records2.

Regards,

Eliot Lee
Quote Reply
Re: num_records with multiple database In reply to
Bingo!

Thank you Eliot!

Valerie
http://www.skymax-usa.com
http://www.ad-ink.com
Quote Reply
Re: num_records with multiple database In reply to
You're welcome.

Regards,

Eliot Lee