#!/usr/bin/perl -wT use strict; use DBI; use CGI; my $q= new CGI; my $dbh; #Database Connect $dbh = DBI->connect( "dbi:mysql:dansite","dan","vindaloo") or dienice("Can't connect: ", $dbh->errstr); if (!$q->param("action")){ linklist(); }elsif($q->param("action") eq "loadpage"){ loadpage(); }elsif($q->param("action") eq "savepage"){ savepage(); }else{ linklist(); } $dbh->disconnect(); sub loadpage{ my $ath; my $linktoprint= substr($ENV{'QUERY_STRING'},24,100); $ath=$dbh->do("update links set visits=visits+1 where urllink=\"$l +inktoprint\"") or dienice($dbh->errstr); print"Location:$linktoprint\n\n"; } sub savepage{ my $category= $q->param("category"); $category=~s/\+/ /g; my $description=$q->param("description"); $description=~s/\+/ /g; my $sth = $dbh->prepare("insert into links values(?,?,?,?)"); $sth->execute($q->param("urllink"),$category,$description,$q->para +m("visits")) or dienice($dbh->errstr); $sth->finish(); print"Location:/addlink.html\n\n"; } sub linklist{ my ($urllink,$urlcategory,$description,$visits,$catttest,$tbkgrnd) +; print "Content-type:text/html\n\n"; my $sth=$dbh->prepare("select urllink,urlcategory,description,visi +ts ". "from links order by urlcategory,description") or dienice("can't execute query ",$dbh->errmsg); $sth->execute; my $cattest = "bb"; print"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" widt +h=\"100%\">\n"; while(($urllink,$urlcategory,$description,$visits)= $sth->fetchrow +_array){ if ($urlcategory ne "Our Site"){$tbkgrnd = "#993300"} else {$tbkgrnd = "#660000"} if ($urlcategory ne $cattest){ if ($cattest ne "bb"){ print"<tr><td colspan=\"3\"><hr noshade style=\"co +lor: AAAAAA\">", "</td></tr>\n"; } print"<tr>\n<td colspan=\"3\" bgcolor=\"$tbkgrnd\">", "<font class=\"littleheader\">$urlcategory</font></td> +</tr>\n"; } print"<tr>\n<td class=\"linkfont\" bgcolor=\"$tbkgrnd\">" "<font size=\"1\"> </font></td>\n", "<td class=\"linkfont\" bgcolor=\"$tbkgrnd\"><font size=\" +1\">", "<a href=\"/cgi-bin/link.pl?action=loadpage&urllink=$urlli +nk\" ", "target=\"_win\">$description</a>", "</font></td>\n<td class=\"linkfont\" bgcolor=\"$tbkgrnd\" +>", "<font size=\"1\"> $visits</font>", "</td>\n</tr>\n"; $cattest = $urlcategory; } print"<tr>\n<td align=\"right\" class=\"linkfont\" colspan=\"3 +\"><font size=\"1\">", "<hr noshade style=\"color: AAAAAA\">Total<br>", "Visits From<br>This Page</font></td>\n</tr>\n", "</table>\n"; $sth->finish(); }
In reply to mySQL Based link list, with click-thru tracking by Hero Zzyzzx
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |