i have a table in database sql like below, and i want to display it based on id and how many record (generation)
+-------------------------------+
| ID | Parent_ID |
+-------------------------------+
| 1 | 0 |
+-------------------------------+
| 2 | 1 |
+-------------------------------+
| 3 | 1 |
+-------------------------------+
| 4 | 2 |
+-------------------------------+
| 5 | 2 |
+-------------------------------+
| 6 | 2 |
+-------------------------------+
| 7 | 2 |
+-------------------------------+
| 8 | 3 |
+-------------------------------+
| 9 | 5 |
+-------------------------------+
| 10 | 7 |
+-------------------------------+
| 11 | 10 |
+-------------------------------+
| 12 | 10 |
.................................
The list goes on..
so if i want to select the ID = 2 and record from 1st generation to 4th generation, the result is gonna be like this
+-------------------------------+
| ID | Parent_ID |
+-------------------------------+
| 2 | 1 | -> 1st generation
+-------------------------------+
| 4 | 2 | -> 2nd generation
+-------------------------------+
| 5 | 2 | -> 2nd generation
+-------------------------------+
| 6 | 2 | -> 2nd generation
+-------------------------------+
| 7 | 2 | -> 2nd generation
+-------------------------------+
| 10 | 7 | -> 3rd generation
+-------------------------------+
| 12 | 10 | -> 4th generation
.................................
the generation is not always from first, so i start select from any generation position, any idea how to do this in php or php laravel using MySQL database?