NFL News NFL | MLB | NHL | NBA #!/usr/bin/perl -w
use strict;
use CGI;
use DBI;
use Template;
my $q = new CGI;
my $dbh = DBI->connect('DBI:mysql:TICKER:localhost:3306','root','kn0tp4ss') or
die "can't connect to db: $!";
# Inputs
my $sport = $q->param('sport') || '';
my $tem = $q->param('tem') || '';
my $nid = $q->param('nid') || 0;
# Is this is specific News Story?
my $output;
if ($nid) {
my $sth = $dbh->prepare(qq{
SELECT TITLE, STORY, time_stamp
FROM NEWSv2
WHERE NID = ?
}) or die "can't prepare: $!";
$sth->execute($nid);
@$output{qw(title story time)} = $sth->fetchrow_array;
$sth->finish;
$output->{story} =~ s/\n\n//g;
$tem ||= 'NEWS_ITEM.html';
}elsif ($sport) {
my $sth = $dbh->prepare(qq{
SELECT NID, DATE, TIME, TITLE
FROM NEWSv2
WHERE SPORT = ?
ORDER BY DATE DESC, TIME DESC
LIMIT 15
}) or die "can't prepare: $!";
$sth->execute($sport);
my %dups;
while (my ($nid, $date, $time, $title) = $sth->fetchrow_array) {
next if $dups{$title};
$dups{$title}++;
my $t = &time_format($date, $time);
push (@{$output->{NEWS}}, [$t, $title, $nid]);
}
$sth->finish;
$tem ||= 'NEWS_LIST.html';
}else{
$$output{ERROR} = "Not Enough Information - Go Back";
$tem ||= 'NEWS_ERROR.html';
}
print "Content-type: text/html\n\n";
my $template = new Template( { INCLUDE_PATH => './templates' });
$template->process($tem, $output) || die $template->error();
exit 1;
sub time_format {
my ($date, $time) = @_;
my($y, $m, $d) = split /-/, $date;
my($H, $M, $S) = split /:/, $time;
return "$m/$d $H:$M";
}
1;
|