Re: Re: [suspicious - maybe spam] [PHP] [suspicious - maybe spam] Categories and subcategories
| From: | Justin | Date: | Fri, 21 Jan 2005 19:15:20 +0000 |
| Subject: | Re: Re: [suspicious - maybe spam] [PHP] [suspicious - maybe spam] Categories and subcategories | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-206971@lists.php.net to get a copy of this message | ||
Jochem Maas wrote:
Phpu wrote:This level of functionality is supported BY any language.Hi, I need to create multiple categories and subcategories using php and mysql. Something like thatits bad practice to state the technology that must be used before you have determined the scope and function of the problem, besides you have to know whether php and mysql are capable of providing a solution to your problem.
Although there are many many ways of doing this I would suggest looking at the Nested Set Model from Joe celko www.intelligententerprise.com/001020/celko.shtml. A google search will bring up a lot more results. In fact Joe has an entire book on do Hierarchies in SQL (called Joe Celko's Trees and Hierarchies in SQL for Smarties) It is a little complicated up front, and there is a lot of housekeeping for inserts but it does have certain advantages for very large datasets. An alternative is this really simple method id path category ========================= 1 1 root level 2 1 category1 3 1 category2 4 1.2 sub cat of category 1 5 1.3 sub cat of category 2 you can actually do nearly any queries you might need allowing you return all node under a level (sql.. where path like '1*'), just the nodes directly under the level (sql.. where path like '1.?') etc..- category 1- subcat 1.1 - subcat 1.2 - subcat 1.2.1 - subcat 1.2.2- category 2 ------------------------ Does anyone know a godd totorial how to create this in pahp and how to make the structure of the database?