• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Building assoc array from query

#1
[eluser]Unknown[/eluser]
Hello fellow CI'ers!

The query I'm trying to build deals with two tables: leaders and followers. I need to organize my DB query in a specific way so that I can properly display in my view in the following example format:

Leader
Follower
Follower
Follower
Leader
Follower
Follower
Follower

My code is a hack job and I'm wondering if there is a better way. Especially one where there is no presentation code in the controller.

Code:
$query = $this->db->get('leader');

foreach ($query->result() as $row)
{            
            // get leader name
            $data['party'][] = '<div id="leader">'.$row->am_firstName." ".$row->am_lastName.'</div>';
            
            
            // get all the golfers under this leader
            $queryFollowers = $this->db->get_where('follower', array('leader_id' => $row->id));
            
            foreach ($queryFollowers->result() as $rowFollowers)
            {
                $data['party'][] = '<div id="followers">';
                $data['party'][] = $rowFollowers->am_firstName." ".$rowFollowers->am_lastName;    
                $data['party'][] = '</div>';                      
            }  
}

#2
[eluser]InsiteFX[/eluser]
Use a Model it's DATA.

You are not stating were you are calling this code from etc.

Enjoy
InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.