Ah. That was the other interpretation that I hoped wasn't it
An easier way to solve this would be:
Forget about the auto-increment.
Get the highest ID before insertion, add 1 and give this id to the new entry for the ID field and the parent field if it's the first in thread. The replies will get that id as parent as well. So all comments in one threads have the same parent ID. Clear?
Now you can use one query, sort by parent and id.
For each row, keep the last id and parent for comparison.
Then create a variable for the padding space.
Now, if in one row the new parent is the ID of the last row then you know you have to add another padding divs to your output.
As long as the parents stay identical keep the number of padding divs.
If the next parent is different without being the id of the previous row then substract one padding div.
Now, ain't that easy?
OK OK, I'll try to write it down but don't blame me if it doesn't work 100%, it's just a sample for what I mean
//Get the highest id
$highest= $db->query("SELECT max(id) as MAXID FROM comments");
$mm = $db->fetch_assoc($highest);
$max = ($mm['MAXID'] + 1);
// Insert one row with a thread starter
$newrow = $db->query("insert into comments (id, parent, text) values (" . $max .", " . $max . ", '" . $text . "'");
//Now get the threads
$all = $db->query("select * from comments order by parent, id");
$padwidth = 8;
while ($sb = $db->fetch_assoc($all)){
if($all['parent'] == $oldid) {
$padwidth += 8;
$oldparent = $all['parent'];
}
elseif($all['parent'] != $oldparent) {
$padwidth -= 8;
}
echo '<div style="padding-left:' . $padwidth . 'px;">' . $text;
$oldid = $all['id'];
}
Something like this. No warranty. Just a rough sketch...
The German PunBB Site:
PunBB-forum.de