performing queries

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
srinivaasan
Forum Newbie
Posts: 12
Joined: Mon Aug 15, 2005 6:03 am
Contact:

performing queries

Post by srinivaasan »

Hello,

Iam srinivaasan, I am a newbie to query. I have a small problem to solve. First of I have a table named [MENUS]
with its fields as (menu_id, menu_parent, menu_title, menu_order).

menu_id : is an unique ID and primary key
menu_parent: is an ID of the parent menu.
menu_title: is the name of the menu.
menu_order: is the order in which the menu is displayed.

For example: I have menus in my site saying. "HOME PROGRAMMING GRAPHICS AUTHORING" etc

Assume that the above menus have the submenus like

for PROGRAMMING -> VISUAL BASIC, PHP, ASP, etc.,

and for GRAPHICS -> PHOTOSHOP, FLASH, etc,.

AUTHORING -> PRIEMERE, etc.,

Can anyone pls help me to solve the query by extracting these menus and arrange it on my site dynamically using a single query from the given table.

Thanks regards

Srinivaasan.



feyd | help others help you, use a better thread subject instead of "[HELP] Pls, help!"
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

read the useful posts thread which is linked to in my signature. You'll find such a solution.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

i would just take a query that selects the whole table then just put it into a multi demensional array and start sorting it with a recursive function.
User avatar
srinivaasan
Forum Newbie
Posts: 12
Joined: Mon Aug 15, 2005 6:03 am
Contact:

Post by srinivaasan »

Thanks a lot! Using a recursive it is working well.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

You may want to try a modified preorder tree traversal algorithm if you want your program to run faster: PHP is not designed to be a recursive language like Lisp.
User avatar
srinivaasan
Forum Newbie
Posts: 12
Joined: Mon Aug 15, 2005 6:03 am
Contact:

Post by srinivaasan »

Thank you very much for the tutorial "Preorder tree travarsel alg.". Now I can get around with any hieriarchy.
Thanks again for your great support.
Post Reply