This is a data design issue, not a PHP issue.
Basically you are creating two subtypes of notes or messages.
One we'll call a basenote, and it is any note that has no parent.
The other is a followup, and it is any note that has a valid parent.
Your data tables need to accommodate these concepts.
Your table structure needs to include a column for a unique messageID -- preferably autoincrement -- and a parentID that may or may not be null.
The SQL to create the table might look something like this:
CREATE TABLE messages (messageid INT not null AUTO_INCREMENT, parentid INT DEFAULT '0' ,
author VARCHAR (80) not null , title VARCHAR (80) not null , body TEXT not null , timestamp
TIMESTAMP not null , PRIMARY KEY (messageid), UNIQUE (messageid)) ;
To retrieve all of the notes that are NOT followups, you would "select * from messages where parentid='0'".
To retrieve a note that is a followup, first set $parentid to the messageid of the basenote. Then do a query that looks like this:
select * from messages where parentid='$parentid';
Add other conditions, sort order, limits, etc., as you see fit.
As has been discussed here before, I don't happen to like threaded message boards. But the parent/child relationship is a very useful one, and I have implemented it in the contexts of folders and discussions in the Prattle discussion system:
http://stonemountain.yi.org/
Feel free to download and read the code.