Gossamer Forum
Home : Products : DBMan SQL : Discussion :

problem with global function

Quote Reply
problem with global function

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.


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

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

But i get this error message:
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!


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

->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).


Gossamer Threads Inc.