#!/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\">&nbsp;&nbsp;</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\">&nbsp;&nbsp;$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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.