?
Solved

Unlimited depth of menu

Posted on 2006-07-02
1
Medium Priority
?
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 10

Accepted Solution

by:
Khanh Doan earned 500 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

770 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