473,573 Members | 2,868 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Showing categorized menus

258 Contributor
Hi everyone
I have a table in MySQL which contains menus and submenus.

Table :
Expand|Select|Wrap|Line Numbers
  1. + ID + Parent ID +    Name     +
  2. | 1  |     0     | Computer    |
  3. | 2  |     0     | furniture   |
  4. | 3  |     1     | Software    |
  5. | 4  |     1     | Hardware    |
  6. | 5  |     3     | Antivirus   |
  7. | 6  |     3     | Multimedia  |
  8. | 7  |     4     | Graphic card|
  9. | 8  |     4     | Hard disk   |
  10. | 9  |     2     | chair       |
  11. | 10 |    2      | Table       |
  12.  

And I need to show this table as menus in my website.

Like this :
Expand|Select|Wrap|Line Numbers
  1. +Computer
  2.      +Hardware
  3.           +Graphiccard
  4.           +Harddisk
  5.      +Software
  6.           +Antivirus
  7.           +Multimedia
  8. +Furniture
  9.      +Chair
  10.      +Table
  11.  
  12.  
Note : The real table is longer than what i'm showing here

Actualy I came up with some ideas but they are a bit complicated ... Like having another column in the MySQL table to keep menu levels and things like that. Some of those ideas might work but I thought maybe there is an easier and more logical way to do this.

Any suggestions will be appreciated

Thanks / Behzad
Oct 10 '09 #1
2 1643
Markus
6,050 Recognized Expert Expert
Interesting. In all my time using PHP, I've never had to do this. It'll require some recursion, and I'll work on a solution over today (when I'm not busy).

Mark.
Oct 11 '09 #2
bnashenas1984
258 Contributor
Hello Markus
Thank you for taking your time to answer to my post.
Actualy I found a way to do it.

Here's what I did:
I made another column in my table (Sort order) which contains the level and the address of each category. my table lokks like this now


Expand|Select|Wrap|Line Numbers
  1. + ID + Parent ID +    Name     +  Sortorder +
  2. | 1  |     0     | Computer    |    0-1      |
  3. | 2  |     0     | furniture   |    0-2      |
  4. | 3  |     1     | Software    |    1-3      |
  5. | 4  |     1     | Hardware    |    1-4      |
  6. | 5  |     3     | Antivirus   |    3-5      |
  7. | 6  |     3     | Multimedia  |    3-6      |
  8. | 7  |     4     | Graphic card|    4-7      |
  9. | 8  |     4     | Hard disk   |    4-8      |
  10. | 9  |     2     | chair       |    2-9      |
  11.  
  12.  

Then all we need to do is to sort the table by (sort order) and print all the queries.

We also need to know the level of each category. It could be several categories inside each other. To do that we could use the length of the (sort order) or just explode it by (-) to know which level we are on.

Expand|Select|Wrap|Line Numbers
  1. $query = mysql_query("SELECT * FROM categories ORDER BY sortorder");
  2.  
  3. while ($sqlresult = mysql_fetch_array($query)){
  4.      print str_repeat(" ",strlen($sqlresult["sortorder"])).$sqlresult["text"];
  5. }
  6.  
and here is the result

Expand|Select|Wrap|Line Numbers
  1. Computer
  2.    Software
  3.       Antivirus
  4.       Multimedia
  5.    Hardware
  6.       Graphic card
  7.       Harddisk
  8. Furniture
  9.    Chair
  10.  
  11.  

When I was finished writing this then I found some other ways on google. They are a little complicated to understand but more logical :P

They call it : Hierarchical data

http://dev.mysql.com/tech-resources/...ical-data.html

I hope this helps someone.
Oct 11 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
2712
by: Marci | last post by:
I found this script for cascading menus, however, I cannot reach the author to solve the bug I am having when I add a second menu to it. My problem is this: If I click on the first link, the menu displays well. If I then click on the second link, the first menu from the first link still displays. How do I get make the first menu...
1
11285
by: cefrancke | last post by:
I have set the Startup properties to the following... All menus, toolbars, etc are turned off plus these are unchecked Allow Full Menus Allow Built-in Toolbars Allow Default Shortcut Menus Allow Toolbar/Menu Changes Use Access Special Keys
3
11488
by: cefrancke | last post by:
The only reason I ask is that no one has made this subject clear or given a definitive answer. What I would like to do is, after turning off all the menus/tbars/etc using the startup options. Upon restarting Access, when an admin is detected (I use a GetSystemUser() function) I want to restore everything so that Access behaves like...
0
3531
by: cefrancke | last post by:
I recently discovered, that if you set the startup options for "security", you will have alot of work do to get Access back to "normal". If you disable the built-in menus/toolbars you'll have to reconstruct the one you want as a custom menu/shortcut(popup)/toolbar. All this was a long journey in order to allow the user to sort/copy on a...
4
1679
by: Karl Irvin | last post by:
I distribute an A 2000 app as a mde. On a few customers, my custom menus are overwritten. The top menu is generally there but the choices on the menus are gone or replaced by something else. I can't figure this one out. Any ideas on what may be causing this? It happens on machines with A 2000 and A 2003, Win Home and Win XP. I've yet to...
3
1772
by: Steven Smith | last post by:
the way I'm undersatnding the MSDN documentation when creating parent and child forms the main menu for the child form should not be displayed on the child form itself but instead be incorporated into the parent forms main menu, however I just cannot make this work, with the parents main menu being displayed at all times, I know this is...
15
2677
missinglinq
by: missinglinq | last post by:
I'd like to use acCmdAppMinimize with two forms on the screen at once. Currently, if I have a form opening the db (with DoCmd.Maximize in the OnLoad event) and then a popup form on top of the first form, the first form vanishes when the second form appears. Alternatively, I like to have both showing with just the Access container showing, with...
2
3491
by: diogenes | last post by:
I have created many shortcut/popup (aka context, or right-click) menus for my application - instead of toolbars or standard drop-down menus. Within my custom menu, I am using =ShowMainMenu("item") in the On Action event where ShowMainMenu is a public function in frmMain, and "item" is a string mapping to a button click event. (error...
0
2903
by: ARC | last post by:
Hello all, For right-click (shortcut) menus in access 2007, I've been using a round-about method of opening access 97 on an old computer, modifying my own custom shortcut menus, then importing the menus only into my access 2007 project. This is proving cumbersome (especially since my old pc with access 97 likes to blue screen when...
0
7755
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7679
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7992
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8190
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7756
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8048
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6385
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3722
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2183
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.