I’m working on a DBman project, and have set up 3 SELECT field dropdowns, which display at the top of the search results page, which give users the opportunity to refine there search by State, Region and City.
This works fine, except that it does 2 searches of the main DB, one for the main search results and one for the dropdowns.
So I decided to integrate the dropdown code into DB.CGI sub query, so it will load the arrays used to generate the dropdowns and the search results with the one search.
This is part of sub query from DB.CGI which will explain whats going on.
open (DB, "<$db_file_name") or &cgierr("error in search. unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
(/^#/) and next LINE; # Skip comment Lines.
(/^\s*$/) and next LINE; # Skip blank lines.
$line = $_; chomp ($line); # Remove trailing new line.
@values = &split_decode($line);
if (!(grep $_ eq $values[1], @states)) {
push (@states, $values[1]);
}
if ($values[1] eq $in{'State'}) {
if (!(grep $_ eq $values[2], @regions)) {
push (@regions, $values[2]);
}
}
if (($values[1] eq $in{'State'}) || ($values[2] eq $in{'Region'})) {
if (!(grep $_ eq $values[3], @cities)) {
push (@cities, $values[3]);
}
}
.
.
(code)
.
.
return ("ok", @hits);
The main search results are returned via @hits to:
sub view_records {
# --------------------------------------------------------
# This is called when a user is searching the database for
# viewing. All the work is done in query() and the routines just
# checks to see if the search was successful or not and returns
# the user to the appropriate page.
my ($status, @hits) = &query("view");
if ($status eq "ok") {
&html_view_success(@hits);
}
else {
&html_view_failure($status);
}
}
and then to sub html_view_success in the HTML.PL thus:
my (@hits) = @_;
What I need to do is return @hits @states @regions and @cities back to sub html_view_success, and extract them.
To do this I need to build an Array of Arrays or List of Lists and return that.
I have done a lot of reading on REFERENCES, and I understand the concept, but I,m really not to sure how to implement it.
Can some one please show me how to return multiple arrays, and extract them as I really can not work this out.
Thanks
Bob
http://totallyfreeads.com
This works fine, except that it does 2 searches of the main DB, one for the main search results and one for the dropdowns.
So I decided to integrate the dropdown code into DB.CGI sub query, so it will load the arrays used to generate the dropdowns and the search results with the one search.
This is part of sub query from DB.CGI which will explain whats going on.
open (DB, "<$db_file_name") or &cgierr("error in search. unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
(/^#/) and next LINE; # Skip comment Lines.
(/^\s*$/) and next LINE; # Skip blank lines.
$line = $_; chomp ($line); # Remove trailing new line.
@values = &split_decode($line);
if (!(grep $_ eq $values[1], @states)) {
push (@states, $values[1]);
}
if ($values[1] eq $in{'State'}) {
if (!(grep $_ eq $values[2], @regions)) {
push (@regions, $values[2]);
}
}
if (($values[1] eq $in{'State'}) || ($values[2] eq $in{'Region'})) {
if (!(grep $_ eq $values[3], @cities)) {
push (@cities, $values[3]);
}
}
.
.
(code)
.
.
return ("ok", @hits);
The main search results are returned via @hits to:
sub view_records {
# --------------------------------------------------------
# This is called when a user is searching the database for
# viewing. All the work is done in query() and the routines just
# checks to see if the search was successful or not and returns
# the user to the appropriate page.
my ($status, @hits) = &query("view");
if ($status eq "ok") {
&html_view_success(@hits);
}
else {
&html_view_failure($status);
}
}
and then to sub html_view_success in the HTML.PL thus:
my (@hits) = @_;
What I need to do is return @hits @states @regions and @cities back to sub html_view_success, and extract them.
To do this I need to build an Array of Arrays or List of Lists and return that.
I have done a lot of reading on REFERENCES, and I understand the concept, but I,m really not to sure how to implement it.
Can some one please show me how to return multiple arrays, and extract them as I really can not work this out.
Thanks
Bob
http://totallyfreeads.com