Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by bradcathey (Prior)
on Mar 17, 2010 at 20:11 UTC ( #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


Comment on Re: HTML::Template nested loops, DBI/MySQL and map
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2014-09-21 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls