#!/usr/bin/perl -Tw ############################################################ ## Written and copyright 2002 by ## Jacqueline D. Hamilton (kira@cgi101.com) ## ## This code is excerpted from "CGI Programming 201" ## (http://www.cgi101.com/advanced) ## ## You may use this code on your own website, however ## you may not publish or sell any copy or derivative work ## without permission of the author. ############################################################# use strict; use lib '.'; use MyBoard; # declare variables my($sth, $rv, $f, $count); my($limit); # untaint the limit count if ($cgi->param('start') =~ /^(\d+)$/) { $limit = $1; } else { $limit = 0; } # how many msgs to display per page my($maxcount) = 5; &do_header($btitle); print qq(

$btitle

\n); my($today) = ""; $count = 0; # delete the forum_id stuff in the query, # alter the date format to read "Thursday, May 8, 2002" # and format the time into "12:30 PM" # $sth = $dbh->prepare("select *,date_format(date, '%W, %M %e, %Y') as nicedate, date_format(date, '%l:%i %p') as nicetime from messages where thread_id=0 order by date desc limit $limit, $maxcount") or &dbdie; $rv = $sth->execute; while ($f = $sth->fetchrow_hashref) { my($asth) = $dbh->prepare("select count(*) from messages where thread_id=$f->{id}"); $rv = $asth->execute; my($r) = $asth->fetchrow_array; my($responses); if ($r == 1) { $responses = "1 comment"; } elsif ($r > 1) { $responses = "$r comments"; } else { $responses = "0 comments"; } if ($f->{nicedate} ne $today) { if ($today ne "") { print qq(
\n); } print qq(

$f->{nicedate}

\n); $today = $f->{nicedate}; } print qq($f->{subject}

\n); # smiliefy is optional... print &smiliefy($f->{message}), qq(

\n); my($author) = &linkify($f->{author}, $f->{email}); print qq(#$f->{id} | Posted by $author at $f->{nicetime} | $responses

\n); $count = $count + 1; } if ($count == 0) { print qq(No messages.

\n); } else { my($prev); if ($limit > 0) { $prev = $limit - $maxcount; if ($prev < 0) { $prev = 0; } print qq(

< Previous $maxcount

\n); } if ($count == $maxcount) { my($next); $next = $limit + $maxcount; print qq(

Next $maxcount >

\n); } } &do_footer;