for (@info) { my %data; my $sth = $obj->DBI->Replies->sql_count; $sth->execute($_->id); my $r = ($sth->fetchrow_array)[0]; $data{author} = $_->author; $data{content} = $_->content; $data{title} = $_->title; $data{id} = $_->id; $data{date} = $_->date; $data{count} = $r; push @loop_data, \%data; } #### SELECT COUNT(*) from __TABLE__ where thread_id=? #### #get the reply count... my $sth2 = $dbh->prepare(q{ select count(*) from dh_replies where thread_id=?}); for ( scalar $rows_data ) { $sth2->execute($_); my $count = $sth2->fetchrow_array; push @$rows_data, { count => $count }; } #### ### get replies ### use each $row's id as the argument passed to execute and retrieve ### reply counts on each message my $sth2 = $dbh->prepare(q{ select count(*) from dh_replies where thread_id=? }); $sth2->execute( $rows->{'id'} ); my $count = ($sth2->fetchrow_array)[0]; my %data; $data{'subject'} = $rows->{'subject'}; $data{'author'} = $rows->{'author'}; $data{'content'} = $rows->{'content'}; $data{'date'} = $rows->{'date'}; $data{'id'} = $rows->{'id'}; $data{'count'} = $count; push @rows_data, \%data; }