You are here: Re: Hierarchical Parent/Child Menu « All PHP « IT news, forums, messages
Re: Hierarchical Parent/Child Menu

Posted by Rik on 05/16/06 00:25

Chris wrote:
> I've been working on a basic Parent/Child Menu where if you click on
> the Parent link the Child set of links appears, then when clicked
> again, it disappears. All the parent/child elements are propagated
> from a MySQL database, and there is only 1 set of children to each
> parent. I have seen dozens of Tree menus, but the links are all
> hard-coded, and have found a few other references for it, but it
> seems that you can't really do it solely in PHP, but with
> Javascript/CSS and an OnClick event.
>
> Much of what I've seen is old (pre-2002) or they refer to some
> commercial menu-building program (why spend $$ on a program that
> generates 20 different kind of menus when you really only need one
> kind? Sort of like buying the entire CD when you only like one song
> on the whole thing.). Could this be done with an if statement -
> perhaps as a PHP function to be called with isset?
>
> There are ways to pass JS variables back and forth with PHP, but I
> would like it to be simpler. I am working with 2 different servers -
> one -the test server-is running PHP 5.1.2 (Win2003), and the other
> -the current production server- is running PHP 4.3.2 (Linux).

The PHP version of your servers don't matter at all in this case. It's a
question of the user's layout, which is indeed controlled bij html&css, and
possibly bij javascript (allthough that should be avoided as much as
possible IMHO, and always make sure ervrything works with javascript turned
off).

Maybe with a bit of tweaking, this is what you are looking for
css/javascript wise?
http://www.positioniseverything.net/css-dropdowns.html

This way, there isn't really a need to transfer variables from PHP to
javascript and back.
Just make nicely nested lists.

> Also, I would like some advice on the db architecture. Should the
> parent & child categories be in the same db table or as separate
> tables (one for Parents/one for Children with a ref back to the
> parent - this is how I'm currently doing it)?

That's how I do it (adjacency list model). Allthough that kind of
hierarchical system is open for debate.
I've nosed around looking for more versatile and robust methods, and came
across the nested set model:
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

I haven't had the time to implement and test such a system though. For
keeping overview, in very small tables, the adjecency list model will do
fine I think.

Using a lot of different tables for essentially the same date isn't the way
to go I'd think, having to create a new tabel for every submenu is
impractical and a waste.

Grtz,
--
Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация