Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Display field from another table

Quote Reply
Display field from another table
Sorry, It's me again.

As I work my way through DBMan SQL 2.0.3 I find myself unable to solve basic problems.

1/ I'm trying to display 4 or 5 fields from one table on another tables add_form.html (or any other html page). I understand that I need to create a sub in the Global Template section and insert the <%tag_name%> in the add_form.html but I don't know the correct coding for the sub.

Could someone please give me an example that includes how to SELECT 4 or 5 fields from a particular table WHERE the logged in user is the owner of both records (rows).

2/ Is it possible for multiple tables to share one Global Template but have different User Templates without copying the global.txt into each template directory? In other words, multiple tables share one global.txt from one directory but use different user templates. A lot of my content is the same and I think it would save a lot of time to share one template for the common items. Or can I use a seperate file or some other method?

Thanks again.

Simon.
Quote Reply
Re: [jai] Display field from another table In reply to
Hi,

An another way is you can add your custom code directly to Dbsql/HTML.pm but the deal is you have to back up this file when you upgrade the Dbsql. We already have a function generate_list built-in that automatically generate a list from another column within the same table. You can change it a little bit to get a list from different table. i.e:
Code:
sub generate_custom_list {
#----------------------------------------------------------------------
my ($col) = @_;
my $tags = GT::Template->tags;
my $row = $tags->{home}->{sql}->table(your_table)->get($col);
my $output = $tags->{home}->{disp}->select ( {
name => $col,
values => $row,
default => $tags->{home}->{cgi}->{$col},
blank => 0 });
return $output;
}
Then have a new tag in your templates like <%Dbsql::HTML::generate_custom_list('list _column')%>
Cheers,

Last edited by:

jean: Mar 4, 2002, 10:19 AM
Quote Reply
Re: [jean] Display field from another table In reply to
Thanks for your reply.

I have added the sub to Dbsql/HTML.pm and changed the table name.

Do I need to change anything in the template tag?

<%Dbsql::HTML::generate_custom_list('list _column')%>


How do I use SELECT and WHERE to get specific fields?

Also do you have any ideas about my second question in my last post?

Thank you.

Simon.