Solved

Unlimited depth of menu

Posted on 2006-07-02
1
339 Views
Last Modified: 2013-12-12
First of all, sry for my bad english, i hope you understand

I have made a menu width 2 depth of submenu.

But i want to make menu what has 3 or more depth submenu.

Example:
http://gen.kostrika.com/screen.jpg
There tehe menu item has writed by hand.

But i want that, PHP makes automaticly the submenu items. And tehe menu items are in MySql database

Thanks

 
0
Comment
Question by:GenTaliaru
1 Comment
 
LVL 10

Accepted Solution

by:
Khanh Doan earned 125 total points
ID: 17026883
From my code :

<?php
//########################### Cat List ###########################//
function catlist()
{
      $cat = array();
      $totalcats = '1';
      $maxid = '1';

      $cat_query = mysql_query("SELECT * FROM songcat ORDER BY displayorder, cat_name ASC");

      while ($cattemp = mysql_fetch_array($cat_query))
      {
            $id = $cattemp['catid'];
            if ($maxid < $id) $maxid = $id;

            $cat[$totalcats]['id'] = $totalcats;
            $cat[$totalcats]['cat_id'] = $cattemp['catid'];
            $cat[$totalcats]['parent_id'] = $cattemp['parent_catid'];
            $cat[$totalcats]['name'] = $cattemp['cat_name'];

            $totalcats++;
      }

      if ($totalcats == '1')
      {
            $cat_list_bit = $vbphrase['music_nocat'];
      }
      else
      {
            for ($cid = '1'; $cid <= $maxid; $cid++)
            {
                  if ($cat[$cid]['parent_id'] == '0')
                  {
                        $cat_id = $cat[$cid]['cat_id'];
                        $cat_name = $cat[$cid]['name'];
                        $par_num = '0';
                        $cat_list_sub = subcat($cat_id, $cat, $maxid, $par_num);

                        $cat_list_bit .= "<b>" . $cat_name . "</b><br><span>" . $cat_list_sub . "</span>";
                  }
            }
      }

      $cat_list = $cat_list_bit;

      return $cat_list;
}

//########################### Sub Categories ###########################//
function subcat($parent_id, $cat, $maxid, $par_num)
{
      for ($sub_id = 0; $sub_id <= $maxid; $sub_id++)
      {
            if ($cat[$sub_id]['parent_id'] == $parent_id)
            {
                  $cat_id = $cat[$sub_id]['cat_id'];
                  $cat_name = $cat[$sub_id]['name'];

                  $sub_cats_ = '';
                  for ($n = '0'; $n <= $par_num; $n++) $sub_cats_ .= '| - ';

                  $sub_cats_sub = subcat($cat_id, $cat, $maxid, $par_num + 1);

                  $sub_cats .= $sub_cats_ . $cat_name . "<br><span>" . $sub_cats_sub . "</span>";
            }
      }

      return $sub_cats;
}

echo catlist();
?>

My table :

CREATE TABLE IF NOT EXISTS songcat (
  catid int(11) NOT NULL auto_increment,
  parent_catid int(11) NOT NULL default '0',
  cat_name varchar(250) NOT NULL default '',
  displayorder INT NOT NULL DEFAULT '0';
  PRIMARY KEY  (catid)
) TYPE=MyISAM;

Goodluck.
Bonmat86.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now