kiat has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to get the columns name of a table. Let's say I've the following sql statement (simplified):
Somewhere in the code, I've:my $sql = qq{ SELECT item1 FROM basket WHERE item LIKE 'a%' UNION SELECT item2 FROM basket WHERE item2 LIKE 'a%' UNION SELECT item3 FROM basket WHERE item3 LIKE 'a%' UNION SELECT item4 FROM basket WHERE item4 LIKE 'a%' ORDER BY 1 };
What I would like to do is to be able to tag the column name to the value for that column. For example:while (my @ary = $sth->fetchrow_array()) { # $ary[0] gives the value of each selected item }
I would like to be able to associate, say, ruby with item3 (the column name).item1 perl item2 python item3 ruby item4 php
When I wrote @$sth->{NAME}, all that I got was item1.
Is there a way to relate a value to its column name?
Many thanks in advance :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl-MySQL get column names
by tachyon (Chancellor) on Nov 07, 2004 at 12:04 UTC | |
by kiat (Vicar) on Nov 07, 2004 at 12:23 UTC | |
|
Re: Perl-MySQL get column names
by pg (Canon) on Nov 07, 2004 at 20:05 UTC | |
by Aighearach (Initiate) on Nov 07, 2004 at 20:35 UTC | |
by kiat (Vicar) on Nov 08, 2004 at 06:27 UTC | |
|
Re: Perl-MySQL get column names
by Aighearach (Initiate) on Nov 07, 2004 at 20:30 UTC | |
by kiat (Vicar) on Nov 08, 2004 at 06:29 UTC |