Pugdog & Alex,
Thanks for your help so far, you've given me some good advice and after reading what you'd said I've now revamped it some more. Hopefully its more in-line with what you've suggested and so far its going well, but I've still got a problem where the search results are not restircted to the category IDs in the list.
Here's the latest version:
search.cgi
# Set catid
$catid = $in->param('catid'); # Blank if not selected from the category page
# Check catgeory ID's for 'only this cat type search'
if ($catid eq ""){$cat_name=""} else {
# Get Category Name
$cat_name = &get_category_name ($catid); # now uses routine already in DB_Utils.pm
# Get a list of category IDs where the name starts with $cat_name
$sub_list = &get_category_id_list ($cat_name); # uses new routine in DB_Utils.pm to get list of IDs
$in->param ( name => 'CategoryID' , value => $sub_list );
}
DB_Utils.pm
New sub to get comma separated list of matching category IDs (hacked from sub get_category_list):
sub get_category_id_list {
# --------------------------------------------------------
# Get a list of category IDs based on match with start of category name.
#
my $value = shift;
my ($query, $sth, $id, $name, $output, $time);
$output = $CATEGORY_LIST{$value};
$time = time();
if (!$output) {
if (! $CATDB) {
$CATDB = new Links::DBSQL $LINKS{admin_root_path} . "/defs/Category.def";
}
$query = qq!
SELECT ID, Name
FROM Category
WHERE Name LIKE '$value%'
ORDER BY Name
!;
$sth = $CATDB->prepare ($query);
$sth->execute() or die "Can't Execute: $DBI::errstr";
while (($id) = $sth->fetchrow_array) {
($output .= "$id, ");
}
$sth->finish;
$CATEGORY_LIST{$value} = $output;
}
return $output;
}
I've also made the changes Alex suggested to Search.pm to add the CategoryID filter.
I've printed the values for $cat_name and $sub_list to the search results screen and they display OK, but the search routine still doesn't restrict found cats/links to those in the category IDs list.
Any help you could offer on the last part would be appreciated.
Thanks again, you guys
All the best
Shaun
Thanks for your help so far, you've given me some good advice and after reading what you'd said I've now revamped it some more. Hopefully its more in-line with what you've suggested and so far its going well, but I've still got a problem where the search results are not restircted to the category IDs in the list.
Here's the latest version:
search.cgi
# Set catid
$catid = $in->param('catid'); # Blank if not selected from the category page
# Check catgeory ID's for 'only this cat type search'
if ($catid eq ""){$cat_name=""} else {
# Get Category Name
$cat_name = &get_category_name ($catid); # now uses routine already in DB_Utils.pm
# Get a list of category IDs where the name starts with $cat_name
$sub_list = &get_category_id_list ($cat_name); # uses new routine in DB_Utils.pm to get list of IDs
$in->param ( name => 'CategoryID' , value => $sub_list );
}
DB_Utils.pm
New sub to get comma separated list of matching category IDs (hacked from sub get_category_list):
sub get_category_id_list {
# --------------------------------------------------------
# Get a list of category IDs based on match with start of category name.
#
my $value = shift;
my ($query, $sth, $id, $name, $output, $time);
$output = $CATEGORY_LIST{$value};
$time = time();
if (!$output) {
if (! $CATDB) {
$CATDB = new Links::DBSQL $LINKS{admin_root_path} . "/defs/Category.def";
}
$query = qq!
SELECT ID, Name
FROM Category
WHERE Name LIKE '$value%'
ORDER BY Name
!;
$sth = $CATDB->prepare ($query);
$sth->execute() or die "Can't Execute: $DBI::errstr";
while (($id) = $sth->fetchrow_array) {
($output .= "$id, ");
}
$sth->finish;
$CATEGORY_LIST{$value} = $output;
}
return $output;
}
I've also made the changes Alex suggested to Search.pm to add the CategoryID filter.
I've printed the values for $cat_name and $sub_list to the search results screen and they display OK, but the search routine still doesn't restrict found cats/links to those in the category IDs list.
Any help you could offer on the last part would be appreciated.
Thanks again, you guys
All the best
Shaun