Welcome Guest, Not a member yet? Register   Sign In
Basic Report output i can't get my head around
#2

[eluser]mddd[/eluser]
You need to JOIN the list of locations to the list of people.
Then you can loop through the results. Each result will contain the person and his/her location.
If the location changes, you know you've gone to the next list of people.
Like so:
Code:
// get the info
$this->db->select('location.title as locationtitle, users.*');
$this->db->from('location');
$this->db->join('users', 'users.location = location.id', 'left');
$list = $this->db->get()->result_array();

// show the info
$currentlocation = '';
foreach ($list as $item)
{
   // show location title if coming into a new location
   if ($item['locationtitle']!=$currentlocation)
   {
      echo '<p><b>'.$item['locationtitle'].'</b></p>';
      $currentlocation=$item['locationtitle'];
   }
   // show item
   echo '<p>'.$item['name'].'</p>';
}
For more info check out Mysql JOIN and after that see the CI manual Active Record page for how you write JOIN in CI.


Messages In This Thread
Basic Report output i can't get my head around - by El Forum - 07-22-2010, 04:30 AM
Basic Report output i can't get my head around - by El Forum - 07-22-2010, 05:24 AM
Basic Report output i can't get my head around - by El Forum - 07-22-2010, 07:55 AM
Basic Report output i can't get my head around - by El Forum - 07-22-2010, 09:42 AM
Basic Report output i can't get my head around - by El Forum - 07-23-2010, 12:45 AM
Basic Report output i can't get my head around - by El Forum - 07-23-2010, 12:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB