This did the trick.

A little easier way to write this would be:

  print join(", ", @{ $sth->{NAME} }), $/;

Thanks for the help,

Ian

[EMAIL PROTECTED] wrote:

>You would have to use some statement handle attributes.
>
>something like this:
>
>for ( $i = 0; $i <= $sth->{NUM_OF_FIELDS}; $i++) {
>       print "$sth->{NAME}->[$i-1]\t";
>}
>print "\n"; # to return at the end
>
>There's probably a more elegant way to do that with attributes but
>that's how I outputted the column names.
>
>Hope this helps,
>Gordon
>
>-----Original Message-----
>From: Ian Harisay [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, May 21, 2002 11:34 AM
>To: dbi-users
>Subject: Dynamically generating column headers
>
>
>Hi,
>Does anyone know how to generate column headers for output based on the
>SQL.
>my $sth = $dbh->prepare("SELECT field1, field2 FROM table1");
>$sth->execute;
>
>print $headers ## how would I do this based on the fields returned??
>
>while ( my $rec = $sth->fetchrow_arrayref ){
>  print join(", ", @{ $rec } ), $/;
>}
>
>Thanks,
>
>Ian
>



Reply via email to