Welcome Guest, Not a member yet? Register   Sign In
how to write nest loop in CI
#1

[eluser]elfkid[/eluser]
Code:
$query = $this->db->query("SELECT * FROM ci_forum_block where fb_parent = 0");
foreach ($query->result() as $row)
{
  
   echo $row->title;
  
$query2 = $this->db->query("SELECT * FROM ci_forum_block where fb_parent = ".$row->fb_id);


}

how to show this

item1
-item2
-item3
-item4

item5
-item6
-item7
#2

[eluser]Dam1an[/eluser]
Is this always only going to be 2 levels deep, or will there possible be more levels, cause if you're going to have more then 2 levels, you'd want to do it recersivly, if not, then a loop will be fine, and you're very close, just another for loop to print the second query result
#3

[eluser]cwt137[/eluser]
look up 'adjacency list sql' on google for some answers on how to do it with one query.
#4

[eluser]Developer13[/eluser]
And it's not a "CI" thing, it's just a logic thing...




Theme © iAndrew 2016 - Forum software by © MyBB