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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel

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

    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("SELEC T * FROM `Groepen';");
    $sth->execute();
    while (my $Content = $sth->fetchrow_hashr ef){
    $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


  • Kevin Collins

    #2
    Re: hashed array in array need the keys... and length

    "Daniel" <dvdoord@planet .nl> wrote in message news:<3f3b9d3c$ 0$49100$e4fe514 c@news.xs4all.n l>...[color=blue]
    > 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("SELEC T * FROM `Groepen';");
    > $sth->execute();
    > while (my $Content = $sth->fetchrow_hashr ef){
    > $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...
    >[/color]

    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

    Comment

    Working...