Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Pulling Through Information from User Table

Quote Reply
Pulling Through Information from User Table
We've got an articles section on our site where we have contributing users who submit these articles. In the links install for those articles, for the article itself there is an author field where we enter the user's username.

Meanwhile in the user's table we have added a field called 'bio'.

We'd like to be able to pull through the user bio of the author from the users table to display on the articles page. And do so in the least convoluted way.

Would we need to create a global for this? Or is there an easier way?

I've tried creating a gobal, but my Perl is beyond awful. Blush

Code:
sub {
my $LinkOwner = shift;
my $db = $DB->table('Users');
return $db->table('Users')->select(['Bio'], { Username => $LinkOwner })->fetchrow_array;
}
Quote Reply
Re: [meso] Pulling Through Information from User Table In reply to
Almost had it :)

get_bio
Code:
sub {
return $DB->table('Users')->table('Users')->select( ['Bio'], { Username => $_[0] })->fetchrow;
}

If you are only gonna use it once on a page, just do:

Code:
<%get_bio($LinkOwner)%>

...or if you want to use it multiple times, I'd recommend setting it as a tag - so you don't have to keep re-doing the queries:

Code:
<%set user_bio = get_bio($LinkOwner)%>

Then call with:

Code:
<%user_bio%>

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!
Quote Reply
Re: [Andy] Pulling Through Information from User Table In reply to
Thanks Andy! Works like a charm.
Quote Reply
Re: [Andy] Pulling Through Information from User Table In reply to
Once adding that global, we realized that we'd be needing to pull through more information from the user's table (other fields). Naturally, we want to avoid adding a new global for each of the fields that need to be pulled through.

Is there perhaps a single global that can be called that would pull through all the fields to the links page. Not to be displayed immediately. But to the point where they can be referenced. So instead of running a global for the fields we could call them directly ie:
Code:
<%User_Bio%> , <%User_Social_Facebook%>
etc

If this would be a big job, please drop me a PM. Smile
Quote Reply
Re: [meso] Pulling Through Information from User Table In reply to
Nah, thats pretty simple :)

Code:
sub {
return { owner => $DB->table('Users')->table('Users')->select( { Username => $_[0] })->fetchrow_hashref }
}

Then just call with:

Code:
<%owner.Bio%>

..or whatever field you want. If you only want specific fields, then just do:

Code:
return { owner => $DB->table('Users')->table('Users')->select( ['Bio','Test','SomethingElse'], { Username => $_[0] })->fetchrow_hashref }

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!
Quote Reply
Re: [Andy] Pulling Through Information from User Table In reply to
Thanks for the response Andy. Excuse my noobness, but just trying to wrap my head around how such a global works.

In the use of this, it will just need to gather the LinkOwner's user table fields.

So say I create a global "get_author_table" and use that:

Code:
sub {
return { owner => $DB->table('Users')->table('Users')->select( { Username => $_[0] })->fetchrow_hashref }
}

If I try call <%owner.Bio%>, it gives a 'no such tag' issue, which is understandable since the get_author_table hasn't been called.

I imagine I'm missing a fundamental piece of knowledge here ;)
Quote Reply
Re: [meso] Pulling Through Information from User Table In reply to
You need to call <%get_author_table($LinkOwner)%> first, before those tags are available :)

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!