Query
SELECT DISTINCT message.id, message.message, comment.cmessage, comment.cid, scomment.sid
FROM message
LEFT JOIN COMMENT ON comment.parent_id = message.id
LEFT JOIN scomment ON scomment.parent_id = message.id
So… what’s the difference between a comment and a sub comment?
Is there a reason you’re storing all these things in an array?
Your query needs ORDER BY clauses. (tsk tsk r937, sleeping at the switch! )
Anyway…using your array…
foreach ($arr AS $row) {
if($row['message_id'] != $curmsgid) {
//Original Message Info Goes Here.
$curmsgid = $row['message_id'];
}
if($row['cid'] != $curcomment) {
//comment Info Goes Here.
$curcomment = $row['cid'];
}
//Subcomment Info goes here.
}
Thanks StarLion, yes difference between comment and subcomment is, one message have multiple comment and one comment have multiple sub comment. i using array for convert it to JSON format.