Hi, here are some points to get started:
You actually have 2 important fields in your DB :
- id will be the primary key and will identify EACH post (it might be a top-level post or a child post). This count MUST begin at 1.
- parentId will identify the parent post of EACH post, for the top-level posts, set it to 0, this will allow you to retrieve top-level posts with a simple "SELECT FROM tb WHERE parentId='0';"
- Then, you have to write a recursive function that will look for all the child posts of a specific post, its prototype will look something like : int searchChild($postId, $depth);
In that function, you'll select all th child posts of the current post ("SELECT FROM tb WHERE parentId='$postId';"), and for each of them you'll call the function itself : searchChild($data[id], $depth); The $depth parameter is useful if you want to indent your posts (to make a tree)...
- To retrieve the top-level posts you'll call it this way : searchChild(0, 0);
You'll certainly have many parameters to add so that it works fine...
Hope this helps, write back if more help needed.