This should be of your interest:
http://www.evolt.org/article/Four_ways_to_work_with_hierarchical_data/17/4047/
Mattias Thorslund wrote --- napísal::
Hi,
I wonder what you think are the best (or "least worst") strategies to store and retrieve hierarchial data (such as a "threaded" discussion or a multi-level menu tree) in MySQL using PHP?
I have been using table structures where each row contains a parent reference, such as:
Table Example:
Field name data type/db flags Coments
=================================================================
RowID int unsigned auto_increment not null (primary key)
ParentRowID int unsigned 0 (or NULL if at top level)
Name varchar(50)
... which is OK for *defining* the hierarchy. However, it's a pain to retrieve the data so that it can be displayed in a nice threaded/sorted way, where children are sorted directly below their parents. I also want the items to be nicely sorted within their own branch, of course.
On MS SQL, I successfully used stored procedures that employ temporary tables and while statements and the like. That method is not available in MySQL (yet), so I'll have to do a lot of the manipulation on the web server instead, using PHP.
Any suggestions?
/Mattias
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php