Basicly, I believe that you should be able to modify the query to get posts by adding
,parentpost.username AS parentpostusername, parentpostuser.username AS parentpostuserusername
to the SELECT part, then right before the WHERE clause, add
LEFT JOIN post AS parentpost ON post.parentid=parentpost.postid LEFT JOIN user AS parentpostuser ON parentpostuser.userid=parentpost.userid
Then in the part to construct the postbit, you would check for a valid parentpostuserusername element in the array, and if it was invalid user parentpostusername instead. I am unsure of the way that PHP represents NULL values in results from mySQL, though, and the query may not work with those changes (I am by no means an expert on mySQL, and the changes add a good deal of complexity to the query).
|