Re: Hierarchies and MySQL with PHP

From: Date: Sun, 27 Jun 2004 17:24:47 +0000
Subject: Re: Hierarchies and MySQL with PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-189119@lists.php.net to get a copy of this message
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


« previous php.general (#189119) next »