Hi, I want to access the category information in the detailed page template. The variable dump did not show any category information. Any tips on what I should be loading? Been searching around for an hour on terms like access category in detailed etc. Not found anything. :(
Sep 6, 2003, 2:05 AM
Veteran / Moderator (18436 posts)
Sep 6, 2003, 2:05 AM
Post #2 of 7
Views: 5143
Try this...
Create a new global called cat_details...
my $LinkID = $_[0];
my $CatID;
my $table = $DB->table('CatLinks');
my $sth = $table->select( { LinkID => $LinkID } ) || return $GT::SQL::error;
while (my $hit = $sth->fetchrow_hashref) {
$CatID = $hit->{CategoryID};
}
my $table = $DB->table('Category');
my $sth = $table->select( { ID => $CatID } ) || return $GT::SQL::error;
my @return_loop;
while (my $link = $sth->fetchrow_hashref) {
push (@return_loop, $link);
}
return { cat_details_loop => \@return_loop };
}
Call it at the top of your HTML template with;
... then when you need to show the data, just use something like;
<%Title%> <BR>
<%ID%> <BR>
<%Description%> <BR>
... etc
<%endloop%>
Just tried it on my dev installation, and it works a charm
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Create a new global called cat_details...
Code:
sub { my $LinkID = $_[0];
my $CatID;
my $table = $DB->table('CatLinks');
my $sth = $table->select( { LinkID => $LinkID } ) || return $GT::SQL::error;
while (my $hit = $sth->fetchrow_hashref) {
$CatID = $hit->{CategoryID};
}
my $table = $DB->table('Category');
my $sth = $table->select( { ID => $CatID } ) || return $GT::SQL::error;
my @return_loop;
while (my $link = $sth->fetchrow_hashref) {
push (@return_loop, $link);
}
return { cat_details_loop => \@return_loop };
}
Call it at the top of your HTML template with;
Code:
<%cat_details($ID)%>... then when you need to show the data, just use something like;
Code:
<%loop cat_details_loop%> <%Title%> <BR>
<%ID%> <BR>
<%Description%> <BR>
... etc
<%endloop%>
Just tried it on my dev installation, and it works a charm

Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Sep 6, 2003, 6:02 AM
Veteran / Moderator (18436 posts)
Sep 6, 2003, 6:02 AM
Post #4 of 7
Views: 5172
Nah, it just works out faster when trying to grab all the details, and also shorted for the global. Otherwise you would need stuff like;
$
$Title = $hit->{Title};
$ID = $hit->{ID};
$Image = $hit->{Image};
.. etc.
and then to return them, you would need;
return { cat_Description => $Description, cat_Title => $Title, cat_ID => $ID, cat_Image => $Image };
...etc.
As you can see, my global is a lot shorted, and works better IMO than doing it all the long winded way
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
$
Code:
Description = $hit->{Description}; $Title = $hit->{Title};
$ID = $hit->{ID};
$Image = $hit->{Image};
.. etc.
and then to return them, you would need;
return { cat_Description => $Description, cat_Title => $Title, cat_ID => $ID, cat_Image => $Image };
...etc.
As you can see, my global is a lot shorted, and works better IMO than doing it all the long winded way

Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Dec 13, 2009, 2:50 AM
Enthusiast (901 posts)
Dec 13, 2009, 2:50 AM
Post #6 of 7
Views: 4772
The problem is here (nph-build.cgi, line 553):
my @cat_cols = grep !$links_cols{$_}, keys %{$DB->table('Category')->cols};
my $sth = $rel->select('Links.*', @cat_cols, 'CategoryID' => $cond);
May someone has an idea how to add:
Select ... "Category.Description as description"?
Then everything should be done.
Code:
Code:
# Only select Category columns that don't conflict with Links columns. my @cat_cols = grep !$links_cols{$_}, keys %{$DB->table('Category')->cols};
my $sth = $rel->select('Links.*', @cat_cols, 'CategoryID' => $cond);
May someone has an idea how to add:
Select ... "Category.Description as description"?
Then everything should be done.