Changing a last five comments box from perl to Scoop box
|
|
By phill , Section Code [] Posted on Tue Aug 13, 2002 at 12:00:00 PM PST
|
|
I've been trying to mold scoop into a better version of what I wrote a while ago and I've hit a stump. Is there a scoop equivilant to this perl code? (it just takes the last 5 comments on a particular story and formats them for a box)
|
here is the code: #!/usr/bin/perl -w
use strict;
use DBI;
# 2002/7/17/16823/3416
my $sid="2002/7/17/16823/3416";
my @com;
my $i=-1;
my $dbh = DBI->connect('DBI:mysql:generic_name', 'bling', 'word up is the codeword')
or die "Couldn't open database: $DBI::errstr; stoppe
d";
my $sth = $dbh->prepare("SELECT uid,comment FROM comments WHER
E sid='$sid' ORD
ER BY date DESC LIMIT 5")
or die "Couldn't prepare statement: $DBI::errstr; st
opped";
$sth->execute() or die "Couldn't execute statement: $DBI::errstr;&n
bsp;stopped";
while ( my ($uid,$comment) = $sth->fetchrow_array() ) {
$i++;
my $sth2=$dbh->prepare("SELECT nickname FROM users WHE
RE uid='$uid'")
or die "Couldn't prepare statement: $DB
I::errstr; stopped";
$sth2->execute() or die "Couldn't execute statement:&n
bsp;$DBI::errstr; sto
pped";
my $nickname=$sth2->fetchrow_array();
$comment=~s/<br>//gi;
$comment=~s/<p>//gi;
$com[$i]="(<a href=\"http://www1.pipebox.net/user/$nickname\">$nickname
</a>) $comment&
lt;br><br>";
}
$dbh->disconnect;
while($i>=0){
print "$com[$i]\n";
$i--;
}
print "[ <a href=\"/comments/2002/7/17/16823/3416/0/post#here\">comment</a&g
t;&
nbsp;]\n";
exit;
And while it may not be pretty, it sure gets the job done. I tried to do something similar to this using the exisiting boxes as a guide but it didn't work.
Any tips? |
|
Story Views
|
26 Scoop users have viewed this story.
|
|