Anita, this is really straightforward, since you've included parent IDs in your table structure.
What you need to do is write a function that accepts $parentID as an argument. It should query the database for items where parentid=$parentid. For each returned item, print out the results and then have the function call itself with the current item's ID. That will, in turn, query the database and take care of the children.
The first time you call the function, pass 0 as the argument. It will go through the db, find all the root items, and apply itself to each tree recursively.
Putting all of this into an HTML table makes it slightly more complicated, but not overly difficult. You need to create a global variable to count rows of intentation. Then, whenever you output an item, you'll need to use that global variable to loop and print out the required number of empty table cells to handle the indentation. When the function exits it should decrement the global variable.
The following example doesn't do HTML tables, but rather indicated the indentation by printing out the ">" character. You can follow the form, though. Notice how $roomlistindent is incremented and decremented:
function roomlist2($parentid)
{
global $roomlistindent;
global $db;
global $prattle_rooms;
$returns = 0;
$result = mysql_db_query($db, "select * from $prattle_rooms where roomparent='$parentid'");
echo"<P>";
while ($rooms = mysql_fetch_object($result))
{
$returns++;
for ($i=0; $i < $roomlistindent; $i++)
echo ">";
echo " <a href=\"prattle.php?roomid=", $rooms->roomid, "\">", $rooms->title,"</a><P>";
// list all my kids
$roomlistindent++;
roomlist2($rooms->roomid);
$roomlistindent--;
}
return $returns;
}
You may need to do some extra queries to figure out the maximum tree depth in order to generate HTML tables this way.