Gossamer Forum
Quote Reply
Links > category global
 
Hi,

Im trying to setup a global that returns the category URL of each link if that category matches a condition.

Each Link in my version of Links SQL has a minimum of two categories (brand and type) its placed in, for example Link 1 - Cat1: Kraft, Cat2: chedder

The way i've setup LSQL im hoping to only display the brand associated with each link eg.

Some Cheese
Price: $5.00
Brand: <a href="/kraft/">Kraft</a>

Im using the following global to display this but LSQL sometimes mixes up the LinkID and CategoryID order so instead of the brand category URL displaying im getting the Type URL.

Code:
sub {
my $tag = shift;
my $table = $DB->table ('CatLinks');
my $sth = $table->select ( { LinkID => $tag->{ID} }, ['CategoryID'] );
my $catID = $sth->fetchrow_hashref;
my $cattable = $DB->table('Category');
my $sth2 = $cattable->select ( { ID => $catID, CategoryType => 'Brand' }, ['Full_Name'] );
my $name = $sth2->fetchrow_array;
my $clean_name = $cattable->as_url($name);
my $url = $CFG->{build_root_url} . "/" . $clean_name . '/';
return $url;
}

I've written the following global to try and get around this:

Code:
sub {
my $tag = shift;
my $table = $DB->table ('CatLinks');
my $sth = $table->select ( { LinkID => $tag->{ID} }, ['CategoryID'] );
while (my ($catID) = $sth->fetchrow_array) {
my $cattable = $DB->table('Category');
my $sth2 = $cattable->select ( { ID => $catID, CategoryType => 'Brand' }, ['Full_Name'] );
if ($sth2 != 0) {
my $name = $sth2->fetchrow_array;
my $clean_name = $cattable->as_url($name);
my $url = $CFG->{build_root_url} . "/" . $clean_name . '/';
}
}
return $url;
}

Which im hoping will cycle through all the CategoryID's associated with each link and only grab the one that set to CategoryType => 'Brand'

Can you spot any error with the way i've set this up?

thanks for your help,

Charlie



Comedy Quotes - Glinks 3.3.0, PageBuilder, StaticURLtr, CAPTCHA, User_Edit_Profile

Subject Author Views Date
Thread Links > category global Chas-a 1553 Jan 30, 2004, 6:19 PM
Thread Re: [Chas-a] Links > category global
afinlr 1501 Jan 31, 2004, 5:16 AM
Post Re: [afinlr] Links > category global
Chas-a 1511 Jan 31, 2004, 6:17 AM