Lets say I have a table names
like this
| id | parent_id | title |
| 1 | 0 | Boys |
| 2 | 0 | Girls |
| 3 | 1 | John |
| 4 | 2 | Mary |
| 5 | 1 | Felix |
| 6 | 5 | Felix-Malcom |
| 7 | 4 | Mary-Mali |
| 8 | 5 | Felix-Edgar |
| 9 | 4 | Mary-Ally |
| 10 | 3 | John-Mack |
What is the best method of printing all this data to look like this:
Boys
John
John-Mack
Felix
Felix-Malcom
Felix-Adgar
Girls
Mary
Mary-Mali
Mary-Ally
How can I print the data like this? Should I use a inner join or do I have to use a loop inside another loop? What can you recommend?
EDIT: I dont know if this changes anything, but I use mariadb