Gossamer Forum
Home : Products : DBMan SQL : Discussion :

problem with global function

Quote Reply
problem with global function
Hi,

in a detailed record view i would like to show a list of related records of another table. I want to do this using a global definition.

This is my code.

Code:
show_reviews

sub {
my $tags = shift;
my $db = $tags->{db};
my $id = $tags->{ID};
my $table = $DB->table('sreviews');
$table->select_options ('ORDER BY create_date', 'LIMIT 5');
my $sth = $table->query({ reviewd_id => $id} );
if ($sth) {
my @output;
while (my $row = $sth->fetchrow_hashref) {
push (@output, $row);
}
return {rev_loop => \@output };
}

}

In the detailed template I use

Code:
<%show_reviews%>
<%loop rev_loop%> <%sreview_id%>: <%review%><br><%endloop%>

But i get this error message:
Quote:
Can't call method "fetchall_arrayref" on an undefined value at c:/home/henning/test/cgi-bin/dbsql201/admin/GT/SQL/Table.pm line 683.

What am I doing wrong?

Thanks for your help!

Henning



Quote Reply
Re: [ktt] problem with global function In reply to
Hi,

->query returns an array ref of array refs by default. I think what you want is:

my $sth = $table->query_sth ( { review_id => $id } );

which will return an $sth that you can call fetchrow, etc, on.

Or you may just want:

my $sth = $table->select ( { review_id => $id } );

The select method is much simpler, query is useful for taking form input and building an sql query out of it (allows you to pass in max hits, page number, sort order, etc).

Cheers,

Alex
--
Gossamer Threads Inc.