Hi there deco: I'm trying to do the same thing myself (Indent posts for a message forum) Here is something I pulled off phpbuilder yesterday:
" Generally speaking, threading is evil. Nevertheless, I'll tell you how to do it. Store the comments in a table. Each comment should have a unique ID. One of the fields should be the ID of a parent. Any comment with a null parent is a root-level comment. Any comment with a parent, obviously, is a followup or child. To display: Write a function getlinks($parentid). If $parentid is not zero, increment a global indentation counter. Select for all comments where parentid=$parentid. For each returned object, loop from 0 to the indentation counter value, printing out an indentation character (a nonbreaking space will do). Then print out the link to the current item and call getlinks() with the current item's unique ID as an argument. At the end of the function, decrement the indentation counter and return. What you've just done is created a recursive function. Call it with an argument of zero: getlinks(0) and it will begin with all the root-level comments. It will follow each item's chain and print out a complete tree-structured set of links. " Or type in "indented" into the phpbuilder search field to find the original thread. If you find a solid way of doing this, please let me know as I'm evaluating wether or not it's actually worth it. Cheers. Russ On Mon, 1 Oct 2001 22:47:30 +0100 deco <[EMAIL PROTECTED]> wrote: > > I'm trying to solve a problem... I have a site divided in areas. Each > area has it's own id, and may have it's own sub-areas. Each sub-area has > it's own sub-areas, etc... > > My will is to return the areas in some cascade order... I can do it > recursively, but it generates too many queries. I was wondering how i could > do this with only one query to the database. > > Here's the structure i have so far: > AREAS (area_id INT; parent_id INT; root_id(??) INT; description > VARCHAR(60)); > > Can anyone help?? Thanks in advance... > > PS: I think this would very similar to a threaded forum... > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > #-------------------------------------------------------# "Believe nothing - consider everything" Russ Michell Anglia Polytechnic University Webteam Room 1C 'The Eastings' East Road, Cambridge e: [EMAIL PROTECTED] w: www.apu.ac.uk/webteam www.theruss.com #-------------------------------------------------------# -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]