Hi,
Try this one (there were a couple of issues with the last global)
my $prefix = 'wp_';
use DBI;
my $dbh = DBI->connect('DBI:mysql:*******', '*******', '*******') || die "Could not connect to database: $DBI::errstr";
my $query = qq|SELECT * FROM ${prefix}comments ORDER BY comment_date DESC LIMIT 10|;
my $sth = $dbh->prepare($query) || die $DBI::errstr;
$sth->execute() || die $DBI::errstr;
my @loop;
while (my $hit = $sth->fetchrow_hashref) {
$hit->{post_title} = get_title($hit->{comment_post_ID});
push @loop, $hit;
}
$sth->finish();
$dbh->disconnect();
return { get_latest_comments => \@loop };
sub get_title {
my $post_id = $_[0];
my $sth = $dbh->prepare(qq|SELECT post_title FROM ${prefix}posts WHERE post_id = $post_id|) || die $DBI::errstr;
$sth->execute() || die $DBI::errstr;
return $sth->fetchrow;
}
}
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Try this one (there were a couple of issues with the last global)
Code:
sub { my $prefix = 'wp_';
use DBI;
my $dbh = DBI->connect('DBI:mysql:*******', '*******', '*******') || die "Could not connect to database: $DBI::errstr";
my $query = qq|SELECT * FROM ${prefix}comments ORDER BY comment_date DESC LIMIT 10|;
my $sth = $dbh->prepare($query) || die $DBI::errstr;
$sth->execute() || die $DBI::errstr;
my @loop;
while (my $hit = $sth->fetchrow_hashref) {
$hit->{post_title} = get_title($hit->{comment_post_ID});
push @loop, $hit;
}
$sth->finish();
$dbh->disconnect();
return { get_latest_comments => \@loop };
sub get_title {
my $post_id = $_[0];
my $sth = $dbh->prepare(qq|SELECT post_title FROM ${prefix}posts WHERE post_id = $post_id|) || die $DBI::errstr;
$sth->execute() || die $DBI::errstr;
return $sth->fetchrow;
}
}
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!