Here's how I'd do it:
my $sth_news = $dbh->prepare("SELECT id, body FROM news");
$sth_news->execute;
$sth_news->bind_columns(\my $news_id, \my $news_body, \my $comments
while ($sth_news->fetch) {
my $sth_comments = $dbh->prepare("SELECT COUNT(id) FROM comments W
+HERE id = ?");
$sth_comments->execute($news_id);
$sth_comments->bind_columns(\my $comments);
$sth_comments->fetch;
print "$news_id, $news_body, $comments";
}
You should look through the
DBI docs for information on binding variables, it's bother faster and (in this case) more readable.
gav^