Most forums use a recursive database table, with an auto-incremented tread id and a parent id.
each top level thread would have a parent id of 0 but the "replies" would have the parent id of the thread stater.
eg:
| Thread_ID | Parent_ID | Title | Body |
| 1 | 0 | Help Me | .... |
| 2 | 1 | RE: Help Me | ........ |
the trick is to write or find a class or function to step through the database and extract the information.
hope this helps