Okay, Bob. I think I have something for you.
This assumes that, when someone does a search, they will have selected a Category, Make or Model.
There are a couple of notes in the code. Be sure to read them and set things accordingly. Also, I'm assuming your field names are
Category,
Make and
Model. If they're not, you'll have to change the variables to match your field names.
Here goes.
First, replace sub html_view_success with the following:
Code:
sub html_view_success {
# --------------------------------------------------------
# This page displays the results of a successful search.
# You can use the following variables when displaying your
# results:
#
# $numhits - the number of hits in this batch of results.
# $maxhits - the max number of hits displayed.
# $db_total_hits - the total number of hits.
# $db_next_hits - html for displaying the next set of results.
#
my (@hits) = @_;
my ($numhits) = ($#hits+1) / ($#db_cols+1);
my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits);
$in{'nh'} ? ($nh = $in{'nh'}) : ($nh = 1);
$page_title = "Search Results";
&html_page_top;
if ($in{'Model'}) {
# Go through each hit and convert the array to hash and send to
# html_record for printing.
if (($db_total_hits == 1) | | ($maxhits == 1)) {
&html_record_long(&array_to_hash(0, @hits));
}
else {
print qq|<p><$font>Your search returned <b>$db_total_hits</b> matches.</font>|;
if ($db_next_hits) { print "<br><$font>Pages: $db_next_hits</font>"; }
$i = 1;
print "<table>";
for (0 .. $numhits - 1) {
print "<tr>";
&html_record (&array_to_hash($_, @hits));
print "</tr>";
++$i;
}
print "</table>";
if ($db_next_hits) { print "<br><$font>Pages: $db_next_hits</font>";}
}
}
elsif ($in{'Make'}) {
&list_models;
}
elsif ($in{'Category'}) {
&list_makes;
}
&html_footer;
&html_page_bottom;
}
Add the following two subroutines to the html.pl file:
Code:
sub list_models {
# --------------------------------------------------------
open (DB, "<$db_file_name") or
&cgierr("error. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;
$model_fieldnum = 4; # Change this to match the field number of your model field
$make_fieldnum = 5; # Change this to match the field number of your make field
foreach $line (@lines) {
chomp($line);
@data = &split_decode($line);
if ($data[$make_fieldnum] eq $in{'Make'}) {
if (!(grep $_ eq $data[$model_fieldnum], @model_list)) {
push (@model_list, $data[$model_fieldnum]);
}
}
}
foreach $model (@model_list) {
$model_link = &urlencode($model);
$make_link = &urlencode($in{'Make'});
print qq|<a href="$db_script_link_url&Make=$make_link&Model=$model_link&view_records=1">$model</a><BR>|;
}
}
Code:
sub list_makes {
# --------------------------------------------------------
open (DB, "<$db_file_name") or
&cgierr("error. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;
$make_fieldnum = 5; # Change this to match the field number of your model field
$category_fieldnum = 3; # Change this to match the field number of your make field
foreach $line (@lines) {
chomp($line);
@data = &split_decode($line);
if ($data[$category_fieldnum] eq $in{'Category'}) {
if (!(grep $_ eq $data[$make_fieldnum], @make_list)) {
push (@make_list, $data[$make_fieldnum]);
}
}
}
foreach $make (@make_list) {
$make_link = &urlencode($make);
$category_link = &urlencode($in{'Category'});
print qq|<a href="$db_script_link_url&Make=$make_link&Category=$category_link&view_records=1">$model</a><BR>|;
}
}
Add the following subroutine to db.cgi
Code:
sub urlencode {
# --------------------------------------------------------
# Escapes a string to make it suitable for printing as a URL.
#
my($toencode) = shift;
$toencode =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
return $toencode;
}
I did check it for syntax errors, but haven't tested it anywhere. I hope this is what you want.
------------------
JPD