I didn't recognise the bit of your code that fetches records from the database, so I'm going to make a whole heap of assumptions in this answer...take from it what you will:
use CGI;
my $q = CGI->new;
my %params = $q->Vars;
my %links = ("red" => "redscript",
"black" => "blackscript");
my $dbh = DBI->connect("DBD:$database:$sid","$user","$pass")
or die "$0 connect " . DBI->errstr;
my $sql = "select detail1, detail2 detail3
from detail_table
where id = ?";
my $sth = $dbh->prepare($sql) or die "$0 prepare $sql " . $dbh->errstr
+;
$sth->execute($params{id}) or die "$0 execute $params{id} " . $dbh->er
+rstr;
print $q->header,$q->start_html,$q->start_table;
while (my @row = $sth->fetchrow_array()) {
print $q->Tr($q->td([$row[0],
$row[1],
$q->a({-href=>"/cgi-bin/$links[$row[0]].pl?id=
+$params{id}"},
"link to $row[0]")
]));
}
print $q->end_table,$q->end_html;
(this code isn't tested for obvious reasons...)
rdfield |