Welcome Guest, Not a member yet? Register   Sign In
multiple query and foreach loop
#5

[eluser]CroNiX[/eluser]
Code:
$data = $this->db
  ->select('client.name, projects.description')
  ->join('projects', 'client.id = projects.client_id')
  //->where(where conditions, if needed)
  ->order_by('client.name')
  ->get('client')
  ->result_array();

View:
Code:
$last_client = null;

foreach($data as $d)
{
  //only list the client name once (category in your case)
  if ($last_client != $d['name'])
  {
    $last_client = $d['name'];
    echo $d['name'] . '<hr>';
  }
  //now list all of their project descriptions (linkurl in your case)
  echo $d['description'] . '<br>';
}


Messages In This Thread
multiple query and foreach loop - by El Forum - 12-27-2013, 05:19 AM
multiple query and foreach loop - by El Forum - 12-27-2013, 09:25 AM
multiple query and foreach loop - by El Forum - 12-27-2013, 09:28 AM
multiple query and foreach loop - by El Forum - 12-27-2013, 10:17 AM
multiple query and foreach loop - by El Forum - 12-27-2013, 10:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB