[dancer-users] Iteration of hash in template.

Yitzchak Scott-Thoennes sthoenna at gmail.com
Thu Oct 1 00:00:24 BST 2015


On Wed, Sep 30, 2015 at 2:41 PM, Richard Reina <gatorreina at gmail.com> wrote:
> Well something somewhat strange has happened. When I do:  print
> Dumper($pats_ref) . "\n"; from the perl module that handles the DB query it
> only prints one row:
>
> $VAR1 = {
>           '8' => {
>                    'ID' => '8',
>                    'ANAME' => 'KOB',
>                    'opp_team' => 'Cardinals',
>                    'YEAR' => '2015',
>                    'date' => '2015-09-04',
>                    'AMOUNT' => '2.00',
>                    'IDD' => '3',
>                    'CHNAME' => 'DWB',
>                    'CHLG_ID' => '12',
>                    'SPONSOR' => 'MPK',
>                    'season' => 'Fall'
>                  }
>         };
>
> This is baffling and very frustrating because when I do the exact same query
> from the MySQL console it yields 3 row and not 1 row.
>
>  ID | CHLG_ID | season | YEAR | date  | opp_team | NAME  | NAME
> | AMOUNT | sponsor |
> +----+---------+--------+------+------------+----------+-----------+-----------------------------+--------+---------+-------------
> |  8 |       9  | Fall   | 2015 | 2015-09-04  | Cardinals    | KOB | AFA
> |   2.00 | MPK |
> |  8 |      12 | Fall   | 2015 | 2015-09-04 | Cardinals     | KOB | DWB
> |   1.00 | RFR  |
> |  8 |      12 | Fall   | 2015 | 2015-09-04 | Cardinals     | KOB | DWB
> |   2.00 | MPK |
> +----+---------+--------+------+------------+----------+-----------+-----------------------------+--------+---------+
>
>  Any insight as to why this might be happening would be greatly, greatly
> appreciated.

You are telling DBI to put the results in a hash by ID.  So later rows
overwrite earlier ones.

You probably want fetchall_arrayref( {} ) instead of fetchall_hashref,
but I don't remember seeing what you want to end up doing with the
data.


More information about the dancer-users mailing list