[dancer-users] Iteration of hash in template.
Richard Reina
gatorreina at gmail.com
Thu Oct 1 01:05:30 BST 2015
2015-09-30 18:00 GMT-05:00 Yitzchak Scott-Thoennes <sthoenna at gmail.com>:
> 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.
>
Yitzchak,
I cannot thank you enough for your suggestion. Yes, fetchall_arrayref( {} )
worked perfectly. I still do not have a good understanding as to when to
use fetchall_hashref and when to opt for fecthall_arrayref() instead. I
really really appreicate your help in getting me straightened out.
Thank you again.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150930/e8ac4005/attachment.html>
More information about the dancer-users
mailing list