Bu şimdi kullanıyorum şeye benzer. Sadece zor kısmı birilerinin yorumuna cevap geldiğinde eklemek için bir sonraki cevap yolunu hesaplarken.
The Example Data
ID | Comment | Path
---+------------------------------+----------
0 | Comment #1 | 01
1 | Comment #1 reply | 01_01
2 | Comment #1 reply reply | 01_01_01
3 | Comment #1 reply reply | 01_01_02
4 | Comment #2 | 02
5 | Comment #3 | 03
6 | Comment #3 reply | 03_01
The Example SQL
SELECT * FROM comments ORDER BY path
The Example PHP
while ($result = mysql_fetch_assoc($query)) {
$nesting_depth = count(explode("_", $result['path']));
$branch = str_repeat("--", $nesting_depth);
echo $branch {$result['comment']}";
}
The Example Result
Comment #1
-- Comment #1 reply
---- Comment #1 reply reply
---- Comment #1 reply reply
Comment #2
Comment #3
-- Comment #3 reply
To make a reply to 01_01
SELECT path FROM comments WHERE path LIKE '01\_01\___'
$last_path = $row[0];
$last_path_suffix = substr($last_path,strrpos($last_path,'_')+1);
$next_path_suffix = str_pad($last_path_suffix+1,2,'0',STR_PAD_LEFT);
$next_path = substr($last_path,0,strlen($last_path)-strlen($last_path_suffix)).$next_path_suffix;