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

Access to fields in EVERY table in db?

Quote Reply
Access to fields in EVERY table in db?
Hey,

how it could be possible to access fields in all tables in the links-sql-db?
e.g. i have a table called "Profiles" and a field in it "Profiles_Age" and i could access this value only with <%Profile_Age%> from every template.

How this could be possible?

Of course i guess, that every field in the tables has different names, otherwise it wouldnt work!

A global would be possible to! e.g.
<%globalname($TableName,$FieldName)%>
But this should be then possible too: <%if globalname($TableName,$Fieldname) eq '18'%>You're 18!<%endif%>

Thanx in advance and Greetings from germany!

Coyu

Last edited by:

Coyu: Mar 28, 2004, 11:56 PM
Quote Reply
Re: [Coyu] Access to fields in EVERY table in db? In reply to
You would probably need something like;

Code:
sub {

my $_table = $_[0];
my $ID = $_[1];

my $table = $DB->table($_table) || return $GT::SQL::error;
my $hash = $table->select( { ID => $ID } )->fetchrow_hashref;

my @loop;
push (@loop,$hash);

return { profile_loop => \@loop };

}

The following code should load the links values (won't produce anything, except the new loop tag);

Code:
<%sub_name('Profiles',$ID)%>

<%loop profile_loop%>
<%if Age > 17%>You are over 17 years old.
<%endloop%>

This is untested, but should work for what you need.

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] Access to fields in EVERY table in db? In reply to
Hi Andy,

ok, but how can i check this:
<%if Age eq '18'%>....<%endif%> ??
Quote Reply
Re: [Coyu] Access to fields in EVERY table in db? In reply to
Erm, exactly how I just showed you ;)

Code:
<%sub_name('Profiles',$ID)%>

<%loop profile_loop%>
<%if Age eq '18'%>You are over 17 years old. <%endif%>
<%endloop%>

You can't do it like;

<%if Age eq '18'%>....<%endif%>

This is a bug in the GT template parser, as it doesn't seem to be able to handle variables being passed into it, when inside an if statement. i.e;

<%if global('12345') eq '1'%>...<%endif%>

..wouldn't work, as 12345 cannot be passed in to the global, when being used with an 'if' statement.

Hope that makes sense.

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] Access to fields in EVERY table in db? In reply to
Hi Andy,

i get this:

A fatal error has occured:
Can't call method "fetchrow_hashref" on an undefined value at (eval 26) line 6.

Please enable debugging in setup for more details.

So i use this in my template:

<%global_name('Users_Profile,$Age)%>

<%loop profile_loop%>
<%if Age eq '17'%>
You are over 17 years old.

Is that correct? I think i made a mistake with the loop?

Greetings,
Coyu
Quote Reply
Re: [Coyu] Access to fields in EVERY table in db? In reply to
Did you actually use;

<%global_name('Users_Profile,$Age)%>

? i.e exact, word for word... cos there is a typo in there Wink

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: [Coyu] Access to fields in EVERY table in db? In reply to
Never mind, I see the problem;

Code:
<%global_name('Users_Profile,$ID)%>

<%loop profile_loop%>
<%if Age eq '17'%>
You are over 17 years old.
<%endif%>
<%endloop%>

Note the $ID in red, it shouldn't have been $Age, as you need to pass in an ID, so it can look the record up Wink

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] Access to fields in EVERY table in db? In reply to
Sorry, but i get again an error!

<%global_name('Users',$ID)%>
<%loop profile_loop%>
<%if Name eq 'Peter'%>
Your name is Peter
<%endloop%>

A fatal error has occured:
Can't call method "fetchrow_hashref" on an undefined value at (eval 26) line 6.

Please enable debugging in setup for more details.

$Username instead $ID brings me the same error!

Coyu
Quote Reply
Re: [Coyu] Access to fields in EVERY table in db? In reply to
Which template are you using this in?

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] Access to fields in EVERY table in db? In reply to
In Reply To:
Which template are you using this in?

Cheers


page.cgi?s=4d228b4d13bd0346ac1b5f1caced9789&p=new_template

A HTML-Page generated by page.cgi

Coyu
Quote Reply
Re: [Coyu] Access to fields in EVERY table in db? In reply to
Erm, well it won't work there then, as you need $ID assigned (only in the detailed and link templates).

Which field, in which table, are you trying to access? And with what condition?

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] Access to fields in EVERY table in db? In reply to
In Reply To:
Erm, well it won't work there then, as you need $ID assigned (only in the detailed and link templates).

Which field, in which table, are you trying to access? And with what condition?

Cheers


A new table with a correct def-file.
No condition! At first i want only to print it out!

Coyu
Quote Reply
Re: [Coyu] Access to fields in EVERY table in db? In reply to
Well, you have to have some way to know which entry you want to grab from the database. For example, in the above, it checks for an entry that has the ID = $ID.

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] Access to fields in EVERY table in db? In reply to
ok!
its the username of the logged in user!