Re: Re: [suspicious - maybe spam] [PHP] [suspicious - maybe spam] Categories and subcategories

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jochem Maas wrote:
Phpu wrote:

Hi,
I need to create multiple categories and subcategories using php and mysql. Something like that


its 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.

This level of functionality is supported BY any language.



- 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?

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..


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux