If you are not worried about the order in which the columns come back, you could select straight into a hash and save a few lines of code - something like this:
my $r_results=$dbh->selectrow_hashref("Select * from $tablename where idnr=?",{},($somenumber)); foreach my $col_name (keys %$r_results) { print "$col_name is $r_results->{$col_name}<br>"; } -----Original Message----- From: JoeJoeJoeJoe [mailto:[EMAIL PROTECTED] Sent: Monday, 22 September 2003 3:23 PM To: [EMAIL PROTECTED] Subject: Better way to get column names with values? Hey, Basically trying to get 1 set of results returned, along with all column names at the same time. Is there an easier way to do it than this? Here's what I have: (Note: MySQL database) my $tablename = "tablename"; #get around taint warning $sql = "LISTFIELDS $tablename"; $sth = $dbh->prepare($sql); $sth->execute; @generic = @{$sth->{NAME}}; @perm = @generic; $sth->finish; $sql = "Select * from tablename where idnr='$somenumber'"; $sth = $dbh->prepare($sql); $sth->execute; @generic = $sth->fetchrow; @results = @generic; $sth->finish; $count = @perm; $i = 0; do { print "$i - $perm[0] is $results[0]<br>"; $i++; } until ($i >= $count); Ignore the last part, it's just an example of what I'm trying to do with the results. I know it's nasty, I do better code than that. ;-) This works, but I'm not sure how well to trust it with it being two separate statements. Is there a better way? I've been working with DBI for quite a while, but haven't had to deal with column names until now. Thanks, Joe -- Now Playing: Joan Jett - Everyday People [From Album (1983)] (1:07/2:41) Powered by XMMS and SuSE Linux 8.2 Pro Australia Post is committed to providing our customers with excellent service. If we can assist you in any way please either telephone 13 13 18 or visit our website www.auspost.com.au. CAUTION This e-mail and any files transmitted with it are privileged and confidential information intended for the use of the addressee. The confidentiality and/or privilege in this e-mail is not waived, lost or destroyed if it has been transmitted to you in error. If you have received this e-mail in error you must (a) not disseminate, copy or take any action in reliance on it; (b) please notify Australia Post immediately by return e-mail to the sender; and (c) please delete the original e-mail.