Gossamer Forum
Home : Products : DBMan : Customization :

Where to install "List Categories"

Quote Reply
Where to install "List Categories"
I'm trying to install the "List Categories" mod, but I keep getting "DBMan Error" messages. I've added the needed subroutine to db.cgi, and I've modified the lines in the mod as listed in the comments.

I'm trying to add it to he html_record_ssi page, but I'm not sure where to put it. Here is the original code:

Code:
sub html_record_ssi {
#---------------------------------------------------
open (DB, "<$db_file_name") or &cgierr("unable to open database: $db_file_name.\nReason: $!");
@lines = <DB>;
close DB;
$in{'mh'} = $#lines;

my (%rec) = @_;
my $font = 'font size=2';
my $font_tiny = 'font size=1';
print qq|
<$font><a href="$db_script_link_url&view_records=1&Artist=$rec{'Artist'}" target="_top">$rec{'Artist'}</a></font><br>
|;
}

How do I add this code in there?

Code:
for ($i = 0; $i <= $#db_cols; $i++) {
#### In the line below, replace 'Category' with the name of your field.
if ($db_cols[$i] eq "Artist" ) {
$fieldnum = $i; $found = 1;
last;
}
}
if ($found) {
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
#### if you are using the validate records mod, uncomment the following line and replace the "4" with the
#### number of your Validated field
# if ($field[4] eq "Yes") {
++$count{$fields[$i]};
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
#### if you are using the validate records mod, uncomment the following line
# }
}
close DB;

foreach $option (sort @options) {
unless ($count{$option}) {
$count{$option} = '0';
}
$encoded = &urlencode($option);
#### if you only want to list categories that have matching entries, uncomment the following line
# if ($count{$option} ne '0') {
#### In the line below, replace 'Category' with the name of your field.
print qq|
<a href="$db_script_link_url&Artist=$encoded&view_records=1">$option</a> ($count{$option})<BR>
|;
#### if you only want to list categories that have matching entries, uncomment the following line
# }
}
}
Quote Reply
Re: [shalom777] Where to install "List Categories" In reply to
I've never used this mod... but it looks like you replace the whole sub (anything below the #------- part) with the new code. (Save a copy first)
Quote Reply
Re: [Watts] Where to install "List Categories" In reply to
You would add the code within the sub where you want the list to display.

In your case, perhaps before the final } which closes off the sub.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Where to install "List Categories" In reply to
I got it to work, but using a slightly different version of the mod that I found listed in this forum:

http://www.jpdeni.com/...listcategories10.txt

Now I have a problem of the list of items showing up over and over again. It shows the list and counts the number accurately, but the 6 items are repeated at least a dozen times. You can see them here:

http://www.fraasfineart.com/code/artists2.shtml
Quote Reply
Re: [shalom777] Where to install "List Categories" In reply to
The version you are using is for categories and subcategories .. is that how your database is setup?

Also I'm wondering if your select field is a multiple select field? If so, there are additional modification to make to have the output done correctly.

I don't see anything wrong with the original code you posted, so I'm wondering it what way it didn't work?

I use several variations of this mod in different databases.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Where to install "List Categories" In reply to
It is setup with categories and sub categories, but it's not the field I'm using for listing.

The database is for an are gallery and I was trying to use this to produce a "on the fly" listing of all the artists on the site. When the client adds or removes an artist, it's automatially removed from the list. I had this working with just a SSI subroutine, but I ran into the problem where if artist XYZ had 5 listings, there name would show up in the list 5 times.

This mod seemed to be my fix, but I'm rather stumped on why I can't get it to work. I read the instructions very carefully, added the needed item to the db.cgi script, used the correct variation, and still no luck. It just gave me a "Internal Server Error". I don't have access to my server error logs with my web host, so I can't check those.

The second version I ran accross, worked fine, except for the fact that the lists keep repeating.
Quote Reply
Re: [shalom777] Where to install "List Categories" In reply to
Since the list category mods were written with using categories I'm not sure you would be able to convert it to use for a field which would contain numerous duplicate field values.

Have you considered using something like having an alpha list link to view by artist? This could be setup as a list of the numbers and letters or as a drop down select list from a static page.

I've done something similar awhile ago for a song lyrics database I helped someone with.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Where to install "List Categories" In reply to
OK, I'm just a bonehead. I'd put the code in the wrong place - now that it's in the correct location, the List Categories thing works perfectly.

Now I just have one additional question about it. Is it possible to limit the results to just one category? The list of items is front the "Artists" field, but the site is broken into sections and I'd like to be able to limit the list to just one category. If I need to have seperate subs for each, that's fine, but I just need to konw how to code it.

I see in the "Modificiations" for DBMan a item from JPDeni on listing sub categories, but it doesn't seem to be quite what I need.