Need help in Mysql Select to show everything under an ID using php.

Hello everyone, I need your help, anyone can give an example code for what I'm trying to do here is, using php and mysql,

Structure of the database: (Figure A)
Line 1 A —
Line 2 B C D
/ | | |
Line 3 E F G H I
/ |
Line 4 J K

Output structure: show in php (Figure B)
Line 1 A ————
Line 2 B C D
| | |
Line 3 E – F – G – J – K H I

Example: J, K is below E, while E is below B, B is below A
I've been trying to find the shortest way out, as shown in Figure B of the Output Structure instead of the database structure shown in Figure A. Any list below E or J will appear in Line 3 at most.

Any help / guide? in php + mysql