Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Displaying field data from different tables

Quote Reply
Displaying field data from different tables
I've searched the forum and can't seem to find a way to show data from a table that I've added.

For example, in my templates, if I want to show the "Contact Name" field of a Link table, I use <%Contact Name%>. That's easy.

But what if I wanted to show the "Color" field from the Breed table?
Quote Reply
Re: [Katana Man] Displaying field data from different tables In reply to
You need a global for this (or a plugin).

How is the entry in the breed table linked to a link?

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Displaying field data from different tables In reply to
To make things easy, the unique key's of the tables are the same: ID

So what might this global look like?
Quote Reply
Re: [Katana Man] Displaying field data from different tables In reply to
It might look like:
Code:
sub {
my $tags = shift;
return $DB->table('Breeds')->get($tags->{ID})->{Color};
}

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Displaying field data from different tables In reply to
Hmm... thank you for the reply... but this isn't going to work well if I want to be able to show data from any field within the Breed table. Defining a global for each field would not be efficient. The Breed table will have 50+ fields.

Last edited by:

Katana Man: Aug 15, 2002, 3:04 PM
Quote Reply
Re: [Katana Man] Displaying field data from different tables In reply to
You asked for Color, I gave you Color.....

Code:
sub {
my $id = shift;
my $field = shift;
return $DB->table('Breeds')->get($id)->{$field};
}
Use as

<%global_name($ID,'Color')%>

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [Katana Man] Displaying field data from different tables In reply to
yogi had it right, if you needed all the fields, you 'd need a global like this

Code:

sub {
my $tags = shift;
my $rec = $DB->table('Breeds')->get( $tags->{ID} );
@$tags{ map { "br$_" } keys %$rec } = values %$rec;
return $tags;
}

If you run that, it should import all the breed columns in with the prefix "br" (just so that they don't override any of the existing tags)

So to display colour would then become <%brColor%>
Quote Reply
Re: [Aki] Displaying field data from different tables In reply to
You've gone hash slice crazy Smile

Last edited by:

Paul: Aug 15, 2002, 4:13 PM
Quote Reply
Re: [Paul] Displaying field data from different tables In reply to
He's trying to show off, after Yogi made him look insignificant after his amazing "TheUsefulPlugin" Wink

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!
Quote Reply
Re: [Andy] Displaying field data from different tables In reply to
Totally right, that just knocked my socks off. Not going to be sleeping tonight with a clean conscience.