hashed array in array need the keys... and length

D

Daniel

By using this code I made an array from a hashed array
to regain a table content and layout as received from a mysql database...

my $sth = $dbh->prepare("SELECT * FROM `Groepen';");
$sth->execute();
while (my $Content = $sth->fetchrow_hashref){
$array[$counter++]=$Content;
}

This part works just fine.. how ever
I need to view the keys (column names) seperatly so
I can put the table together on a webpage...
also length of the hashed array would be nice
so I could make it more dynamic...

Any suggestions please ?S?

Thanks

Daniel
 
K

Kevin Collins

Daniel said:
By using this code I made an array from a hashed array
to regain a table content and layout as received from a mysql database...

my $sth = $dbh->prepare("SELECT * FROM `Groepen';");
$sth->execute();
while (my $Content = $sth->fetchrow_hashref){
$array[$counter++]=$Content;
}

This part works just fine.. how ever
I need to view the keys (column names) seperatly so
I can put the table together on a webpage...
also length of the hashed array would be nice
so I could make it more dynamic...

Actually, what you created is an array of hash references... You can
get the column names a couple of ways:

# non-ordered list of field names as an array
# this will need to be in your loop
@cols = keys(%{$Content});

OR

# ordered list of field names as an array ref.
$cols_ref = $sth->{NAME}

You'll have to post more info on what you want to do with the column
names for anything more than that.

Not sure what you are asking for by "length"... what you are storing
is a reference to a hash.

Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top