Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: HTML::Template nested loops, DBI/MySQL and map

by bradcathey (Prior)
on Mar 17, 2010 at 20:11 UTC ( [id://829264]=note: print w/replies, xml ) Need Help??


in reply to HTML::Template nested loops, DBI/MySQL and map

Another way to do it, though not as slick, but more readable, IMHO:

my $stmt = 'SELECT title, id FROM stages_stage ORDER BY id'; my $stages = $dbh->selectall_arrayref($stmt, {Slice => {}}); $stmt = 'SELECT title, stage_id FROM stages_topic ORDER BY stage_id'; my $topics = $dbh->selectall_arrayref($stmt, {Slice => {}}); for my $i ( 0 .. $#$stages ) { $list->[$i]{'stage_title'} = $stages->[$i]{'title'}; $ictr = 0; while ( $topics->[$tctr]{'stage_id'} == $stages->[$i]{'id'} ) { $list->[$i]{'topics'}->[$ictr]{'topic_title'} = $topics->[$tctr] +{'title'}; $tctr++; $ictr++; } } Dumper: $VAR1 = [ { 'stage_title' => 'Visualize Your Life', 'topics' => [ { 'topic_title' => 'Your Mind' }, { 'topic_title' => 'Your Identity' }, { 'topic_title' => 'Your Security' } ] }, { 'stage_title' => 'Choose Your Buyer', 'topics' => [ { 'topic_title' => 'Yourself' }, { 'topic_title' => 'Employee(s)' }, { 'topic_title' => 'Co-Owner' }, { 'topic_title' => 'Family' }, { 'topic_title' => 'Third-Party' } ] }, ];

—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://829264]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2024-03-28 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found