Example of front end web development base perl

#!D:/usr/bin/Perl/Perl5.14.2/bin/perl.exe

use strict;
use DBI;
use CGI;


my $q = new CGI;
#my $q = CGI->new;
my $topicID = $q->param('id');
print "Topic ID: $topicID\n";

print "Content-type: text/plain; charset=GBK\n\n";

#my($dbh) = DBI->connect("DBI:mysql:it-community", "root", "password", "") or die "can't connect!\n";
my $dbh = DBI->connect("DBI:mysql:database=it-community;host=localhost", "root", "password", {'RaiseError'=>1});

$dbh->do("SET character_set_client = 'gbk'");
$dbh->do("SET character_set_connection = 'gbk'");
$dbh->do("SET character_set_results= 'gbk'");



my $sql = "select uuid, comments, submitter, UNIX_TIMESTAMP(timestamp) creation_timestamp from topic_tie where topic_id='".$topicID."'";
my $sth = $dbh->prepare($sql);
$sth->execute();

# print "======================================================================================================================\n";


# <tr>
# <td>楼主</td>
# <td>
#     <div style="width: 100%; border-radius: 6px 6px 6px 6px; -moz-border-radius: 6px 6px 6px 6px; border: 1px solid silver;">
#         <div style="height: 28px; width: 100%; border-radius: 6px 6px 0px 0px; -moz-border-radius: 6px 6px 0px 0px; border: 1px solid silver;">
#             <span style="line-height: 28px;"><label>标题:</label></span>
#         </div>
#         <div style="height: 28px; width: 100%; border-radius: 0px 0px 6px 6px; -moz-border-radius: 0px 0px 6px 6px; border: 1px solid silver;">
#                           
#         </div>
#     </div>
# </td>
# </tr>


# <tr>
#     <td width="150"></td>
#     <td><a href="">回复主题</a></td>
# </tr>

#while (my @array=$sth->fetchrow_array())
#{
# printf("%-35s", $_) foreach(@array);
# print "\n----------------------------------------------------------------------------------------------------------------------\n";
#};

my $ttt = time();
while (my $ref = $sth->fetchrow_hashref()) {
    print ("<tr>\n");
    print "<td>\n";
    print "$ref->{'deliver'}\n";
    print "</td>\n";

    print "<td>\n";
    print "<div style='width: 100%; border-radius: 6px 6px 6px 6px; -moz-border-radius: 6px 6px 6px 6px; border: 1px solid silver;'>\n";
    print "<div style='height: 28px; width: 100%; border-radius: 6px 6px 0px 0px; -moz-border-radius: 6px 6px 0px 0px; border: 1px solid silver;'>\n";
   
    print "<span style='line-height: 28px;'>\n";
    print "<label>\n";
    print "标题:\n";
    my $_id = $ref->{'uuid'};
    my $_timestamp = $ref->{'creation_timestamp'};
    my $temp = $_timestamp + 86400;
    #print ("</tr>$_timestamp     $temp   $ttt\n");
    if ($temp >= $ttt) {
        print ("<img src='images/new_icon.gif' title='最新论坛主题!'/>");
    }
    print "<a href='tp.shtml?id=".$_id."'>".$ref->{'name'}."</a>(于$ref->{'last_updatetime'}更新)\n";
    print "</label>\n";
    print "</span>\n";
    print "</div>\n";
    print "<div style='height: auto; width: 100%; border-radius: 0px 0px 6px 6px; -moz-border-radius: 0px 0px 6px 6px; border: 1px solid silver;'>\n";
    print "$ref->{'comments'}\n";
    print "</div>\n";
    print "</div>\n";
    print "</td>\n";
    print ("</tr>\n");


    print "<tr>\n";
    print "<td width='150'></td>\n";
    print "<td><a href=''>主页</a>|<a href=''>资料</a>|<a href=''>短信</a>|<a href=''>留言</a>|<a href=''>关注</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=''>好</a>|<a href=''>差</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=''>引用</a>|<a href=''>收藏</a></td>\n";
    print "</tr>\n";
}


# while (my $ref = $sth->fetchrow_hashref()) {
#    print "uuid: $ref->{'uuid'}\n";
#    print "commects: $ref->{'comments'}\n";
#    print "descr: $ref->{'descr'}\n";
#    print "username: $ref->{'username'}\n";
#    print "------------\n";
#}

# print "======================================================================================================================\n";
$dbh->disconnect();
exit 0;

猜你喜欢

转载自lobin.iteye.com/blog/1564141