I'm just trying to clear a doubt I have. I would like to know if I'm doing this right or if there is a better way to optimize my queries. I have 2 simple tables
Parents
------------------------
+ id +    title        +
------------------------
+ 1  +  title parent 1 +
------------------------
+ 2  +  title parent 2 +
------------------------
and so on...
Children
--------------------------------------------
+ id + parent_id +  child_text             +
--------------------------------------------
+ 1 +     1      +   some test             +
--------------------------------------------
+ 2 +     1      +   more text...          +
--------------------------------------------
+ 3 +     2      +  other text             +
--------------------------------------------
+ 4 +     2      +  some more other text...+
--------------------------------------------
and so on... you get it...
The result I want and get is:
Title parent 1
    some text
    more text
Title parent 2
    other text
    some more other text
But at the cost of looping a query into another with something like:
foreach(getParents() as $parent){ //getParents selects all the parents
    getChildren($parent['id']);  // selects all children where parent_id= $parent['id']    
}
I'm wondering if putting a query into a loop that way is bad practice or not and if there is a better way of doing this, maybe with one query only.
 
    