Gossamer Forum
Home : Products : DBMan : Customization :

Modifying Category Listing

Quote Reply
Modifying Category Listing
Hi Carol and Everyone,

I am back working on my Classified Ads project. I am experiencing difficulties inserting the following code into the browse_cat sub-routine that I have
written:

Code:
unless ($data[3] eq "Yes")

BEFORE

Code:
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Category") {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierr("No Category field defined");
}
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 (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
++$count{$fields[$fieldnum]};
}

close DB;

I also tried the following variations with that code.

Examples:

Code:
unless ("Category" eq 'Yes')

AND

Code:
unless ($rec{'Category'} eq "Yes")

AND

Code:
unless ($rec{'Validate'} eq "Yes")

AND

Code:
unless ("Validate" eq 'Yes')

None of this works.

I get syntax errors with everything I try.

ALSO, I need to find a way to modify the sub num_records sub-routine in the db.cgi (index.cgi) file. I have the following codes in place:

Code:
sub num_records {
# --------------------------------------------------------
# Displays the number of records

($per_admin) or ($in{'Validate'} = "Yes");
my $count = 0;

open (DB, "<$db_file_name") or &cgierr("error in num_records. unable to open database:
$db_file_name.\nReason: $!");
LINE: while (<DB> ) {
if (!(/^#/) && !(/^\s*$/)) {
$count++;
}
}
print $count;
}


The bolded line is what I added thinking that it would only show the number of validated records for general users, and the total number of records in the database for administrators. Yet, it shows the same number for both. Hmm...

If you have time, I would really like your assistance or anyone else who knows how I can modify the category listing to only include "validated" records.

TIA.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited August 14, 1999).]

[This message has been edited by Eliot (edited August 14, 1999).]

[This message has been edited by Eliot (edited August 14, 1999).]
Quote Reply
Re: Modifying Category Listing In reply to
According to my book, the syntax is:
EXPRESSION unless (CONDITION);

This is the compact way of saying:
if (! CONDITION) {
EXPRESSION;
}

Hope this helps Smile
TimRyan
Quote Reply
Re: Modifying Category Listing In reply to
With your first question, I assume you want to list the categories where the Validated field equals "Yes." Yes?

If so, try

Code:
@fields = &split_decode ($line);
if ($data[3] eq "Yes") {
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
++$count{$fields[$fieldnum]};
}
}
close DB;

With your second problem, your "or" statement probably does what you want it to do. It just doesn't have any effect on the count, since you don't refer to $in{'Validate'} in the count routine.

I would try

Code:
if ($per_admin) {
++$count;
}
else {
if ($data[3] eq "Yes") {
++$count;
}
}

I think you will do better if you have the ++ in front of $count. I can't explain the difference, but there is one, and having the ++ in front works.


------------------
JPD





Quote Reply
Re: Modifying Category Listing In reply to
Okay...I am a bit confused...The number for my "Validate" field is 25. I tried using [3] and [25] in both modifications and I am not getting the ideal results....

What I get for the browse_cat in html.pl is nothing...No listing of categories at all using these codes:

Code:
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Category") {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierr("No Category field defined");
}
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 ($data[3] eq "Yes") {
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
++$count{$fields[$fieldnum]};
}

}
close DB;

The bolded codes are what I added from Carol's suggestion.

In the sub num_records in the db.cgi (index.cgi for me) file is the same results as before. The total number of records are recorded at 9 rather than 7, which are the total number of Validated records with "Yes", using these codes:

Code:
sub num_records {
# --------------------------------------------------------
# Displays the number of records

if ($per_admin) {
++$count;
}
else {
if ($data[3] eq "Yes") {
++$count;
}
}

my $count = 0;
open (DB, "<$db_file_name") or &cgierr("error in num_records. unable to open database:$db_file_name.\nReason: $!");
LINE: while (<DB> ) {
if (!(/^#/) && !(/^\s*$/)) {
$count++;
}
}
print $count;

}

Again, the bolded lines are the codes suggested by Carol.

Any ideas?? Smile

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Modifying Category Listing In reply to
I assumed, since you had used

unless ($data[3] eq "Yes")

that your "Validate" field was field 3. I guess I was wrong. Smile

Substitue $data[25] for $data[3]. (BTW, what's in field 3?)


------------------
JPD





Quote Reply
Re: Modifying Category Listing In reply to
Hi Carol,

Field [3] is my "Category" field. I tried replacing the [3] with [25] for the "Validate " field and no go...still experiencing bugs.

In the Browse Categories page, no categories are listed. For the number of records, I get 9, rather than 7 (total validated records).

Hmm....*scratches head* *thinks about dinner*

Smile

I think I will take a break for a bit...go get some dinner and revisit this later.

Thanks so much for your assistance. I really appreciate it.

May be when I leave and come back, it will mysteriously work like so many other mods I've installed. Smile LOL!

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Modifying Category Listing In reply to
My fault. I was unclear.

Try this:

Code:
sub num_records {
# --------------------------------------------------------
# Displays the number of records
my $count = 0;
open (DB, "<$db_file_name") or &cgierr("error in num_records.
unable to open database:$db_file_name.\nReason: $!");
LINE: while (<DB> ) {
if (!(/^#/) && !(/^\s*$/)) {
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if ($per_admin) {
++$count;
}
elsif ($fields[25] eq "Yes") {
++$count;
}
}
}
close DB;
print $count;
}

Found some problems with your variables in the both of the subs. This should be correct.

Code:
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Category") {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierr("No Category field defined");
}
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 ($fields[25] eq "Yes") {
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
++$count{$fields[$fieldnum]};
}
}
close DB;

Ya gotta watch them variable names. Smile


------------------
JPD







[This message has been edited by JPDeni (edited August 14, 1999).]

[This message has been edited by JPDeni (edited August 14, 1999).]
Quote Reply
Re: Modifying Category Listing In reply to
Thanks, Carol.

It worked like a charm. I did delete all the records from this test database to start over from scratch to make sure that everything is functioning correctly.

But it works! Smile

Thanks.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Modifying Category Listing In reply to
Okay...The Multiple Select Field mod works fine...However, it has negative affects on some of the other mods I have in place, including the Browse Categories.

I was wondering if there is a way to only list categories ONCE and not have duplicate listings show up. For example, I now have the following in my Browse Categories list:

Academic
Academic|Archaeology
Applied
Biological
CRM
Development
Medical
Psychological

See, Academic shows up twice, because the following codes takes all the values within the "Category" field. I was wondering if there is a way to state that if there are multiple values, only take the first one before the ~~.

Code:
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Category") {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierr("No Category field defined");
}
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 ($fields[25] eq "Yes") {
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
++$count{$fields[$fieldnum]};
}
}
close DB;

In addition, I was wondering if there is a way to adjust the number of records to show total number of records that each category has, not unique number of records for instances within that field. For instance, here is the complete listing with record numbers:

Academic: (2)
Academic|Archaeology: (1)
Applied: (1)
Biological: (2)
CRM: (1)
Development: (1)
Medical: (1)
Psychological: (1)

It should read:

Academic: (3)
Archaeology: (1)
Applied: (1)
Biological: (2)
CRM: (1)
Development: (1)
Medical: (1)
Psychological: (1)

Does this make sense?

Thanks.

Regards,





------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Modifying Category Listing In reply to
I think the below will solve both of your problems.

Instead of

Code:
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
++$count{$fields[$fieldnum]};

Use

Code:
@values = split (/\Q$db_delim\E/o, $fields[$fieldnum]);
foreach $value (@values) {
if (!(grep $_ eq $value, @selectfields)) {
push (@selectfields, $value);
}
++$count{$value};
}


------------------
JPD







[This message has been edited by JPDeni (edited August 23, 1999).]
Quote Reply
Re: Modifying Category Listing In reply to
Carol,

I tried the codes and I got this error message:

Code:
Can't call method "Q" without a package or object reference

So, I added two escape characters / hoping that would work and it didn't. Frown I got the following error:

Code:
Error Message : Error loading required libraries.
Check that they exist, permissions are set correctly and that they compile.
Reason: In string, @months now must be written as \@months

So, I looked at the sub split_decode routine in db.cgi and found these codes:

Code:
my (@array) = split (/\Q$db_delim\E/o, $input);

I thought...ahha! This may be the correct syntax...so, I changed the split statement to the following:

Code:
@values = split (/\Q$db_delim\E/o, $fields[$fieldnum]);

And...*drumroll* It worked!

The codes should be:

Code:
@values = split (/\Q$db_delim\E/o, $fields[$fieldnum]);
foreach $value (@values) {
if (!(grep $_ eq $value, @selectfields)) {
push (@selectfields, $value);
}
++$count{$value};
}

Yea! Smile

Thanks again, Carol!

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Modifying Category Listing In reply to
Glad you found the error. I'll fix it in the original, too.


------------------
JPD