MySQL Forums
Forum List  »  Perl

How to return field Name with value?
Posted by: pcbcad
Date: September 12, 2006 08:39AM

Hi

The following code successfully returns all of the defined values within a record. Every record has a differnt quantity of defined values, some may have 3 values another may have 10, etc.

This means that it is difficult to know which value relates to which field.

Is it possible to return not only the array of defined values but also the associated Field names?

Many thanks
NJH

#-------------------------------------------------
# prepare and execute query
my $query = "SELECT * FROM sr_main WHERE symreq = '$sr_num'";
my $sth = $dbh->prepare($query) or die "Couldn't prepare statement: " . $dbh->errstr;
$sth->execute();

#-------------------------------------------------
# assign fields to variables
my @results = $sth->fetchrow_array();

#-------------------------------------------------
# Print debug information
print $q->b("Data from MySQL");
print $q->p("SR number : $sr_num");

#-------------------------------------------------
# Print SQL output
#print $q->table({ -border => 1},$q->Tr([$q->td([$result1, $result2]),]));
my $field;
foreach $field (@results){print $q->p("$field")}

Options: ReplyQuote


Subject
Written By
Posted
How to return field Name with value?
September 12, 2006 08:39AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.