Selecting nested record on PHP MySQL -
i have table in database sql below, , want display based on id , 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 | ................................. list goes on..
so if want select id = 2 , record 1st generation 4th generation, result gonna 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 not first, start select generation position, idea how in php or php laravel using mysql database?
Comments
Post a Comment