Gossamer Forum
Home : Products : DBMan SQL : Discussion :

select query

Quote Reply
select query
I'm trying to accomplish the following query using a global and return the result to be printed in my template:

SELECT db_data.Variable_A
FROM db_data
WHERE db_data.ID = 'Variable_B'

I want to pass in Vaiable_A (the column that the data I want to retrive is in) and Variable_B, which is a currently available template variable. Variable_A will be a string. This is the global code:

lotdatasub {
my $tags = shift;
my $db_column = $tags->{db_column};
my $id = $tags->{LOTID};
my $table = $DB->table('db_data');
my $sth = $table->select ( { db_column=> $id } );
return $sth;
It is called in the template with the following code: <%lotdata('Title1',LOTID)%> where Title1 is Variable_A and LOTID is the current template variable. I want the data in column 'Title1' in the database db_data to be printed where I call the global. I get the following error: Can't use string ("Title1") as a HASH ref while "strict refs" in use at (eval 17) line 3.Any help would be appreciated. Thanks!
Quote Reply
Re: [mrsnyder] select query In reply to

You should change scripts like:
my $rs = $table->get( { $db_column=> $id } );
return $rs->{$db_column};

And your template should be:
<%set db_column = 'Title1'%>


Quote Reply
Re: [TheStone] select query In reply to
Thanks for the help!