in reply to Re: Extracting Data
in thread Extracting Data

The link would go to another script. The data would come from the record itself. Basically the page loads and pulls records from a database. At the end of each record displayed, I want to have a link that people can click on. For example record 6 is a black hat and record 5 is a red hat. If someone clicks on the black hat I want to use that info not the info for the red hat, if that makes any sense.

Replies are listed 'Best First'.
Re: Re: Re: Extracting Data
by rdfield (Priest) on Dec 12, 2002 at 09:43 UTC
    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