I would like to make a tree menu with category and sub category in Php. When i click on category then display subcategory with link that subcategory page. it is with mysql database. I m tiered to make this but i can't. Please help me. I m providing a Example.......
softx 0 Newbie Poster
I have created a tree menu. This is working properly but when i click into a subcategory that subcategory page is not display. How can i add a page link into a subcategory.
My sql database structure is :
DROP TABLE IF EXISTS `category`;
CREATE TABLE IF NOT EXISTS `category` (
`rowid` bigint(20) NOT NULL AUTO_INCREMENT,
`category_id` bigint(20) NOT NULL,
`category_name` varchar(100) NOT NULL,
`language` char(2) NOT NULL DEFAULT 'EN' COMMENT 'english or french',
`parent_id` bigint(20) NOT NULL DEFAULT '0',
`level` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`rowid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=56 ;
--
-- Dumping data for table `category`
--
INSERT INTO `category` (`rowid`, `category_id`, `category_name`, `language`, `parent_id`, `level`) VALUES
(1, 1, 'Information Technology', 'EN', 0, 0),
(2, 2, 'Graphic Design', 'EN', 0, 0),
(3, 3, 'Business Consulting', 'EN', 0, 0),
(4, 4, 'Administrative Support', 'EN', 0, 0),
(5, 5, 'Other Services', 'EN', 0, 0),
(6, 6, 'Informatique', 'Fr', 0, 0),
(7, 7, 'Conception Graphique ', 'Fr', 0, 0),
(8, 8, 'Conseil en Affaires', 'Fr', 0, 0),
(9, 9, 'Assistance Administrative ', 'Fr', 0, 0),
(10, 10, 'Autres Services ', 'Fr', 0, 0),
(11, 11, 'Web Design', 'EN', 1, 1),
(12, 12, 'Application Design', 'EN', 1, 1),
(13, 13, 'Database Development', 'EN', 1, 1),
(14, 14, 'EXCEL (macros, reports, etc...)', 'EN', 1, 1),
(15, 15, 'Apple Programming', 'EN', 1, 1),
(16, 16, 'Other IT', 'EN', 1, 1),
(17, 17, 'Graphic Design', 'EN', 2, 1),
(18, 18, 'Photo, Video', 'EN', 2, 1),
(19, 19, 'Logos Design', 'EN', 2, 1),
(20, 20, 'Signage and Advertising Design', 'EN', 2, 1),
(21, 21, 'Business Cards Design', 'EN', 2, 1),
(22, 22, 'Other', 'EN', 2, 1),
(23, 23, 'Finance', 'EN', 3, 1),
(24, 24, 'Sales and Marketing ', 'EN', 3, 1),
(25, 25, 'Accounting', 'EN', 3, 1),
(26, 26, '6 Sigma', 'EN', 3, 1),
(27, 27, 'Other', 'EN', 3, 1),
(28, 27, 'Personal Assistant', 'EN', 4, 1),
(29, 28, 'Translations', 'EN', 4, 1),
(30, 29, 'Word, PowerPoint, etc...', 'EN', 4, 1),
(31, 31, 'Other', 'EN', 4, 1),
(32, 32, 'Other', 'EN', 5, 1),
(33, 33, 'Conception de Sites Web ', 'Fr', 6, 1),
(34, 34, 'Conception d''Applications', 'Fr', 6, 1),
(35, 35, 'Développement de base de données ', 'Fr', 6, 1),
(36, 36, 'EXCEL (macros, rapports, etc...) ', 'Fr', 6, 1),
(37, 37, 'Programmation Apple ', 'Fr', 6, 1),
(38, 38, 'Autre', 'Fr', 6, 1),
(39, 39, 'Infographie', 'Fr', 7, 1),
(40, 40, 'Photo, Video', 'Fr', 7, 1),
(41, 41, 'Logos', 'Fr', 7, 1),
(42, 42, 'Enseignes Publicitaires ', 'Fr', 7, 1),
(43, 43, 'Cartes de visite', 'Fr', 7, 1),
(44, 44, 'Autre', 'Fr', 7, 1),
(45, 45, 'Comptabilité', 'Fr', 8, 1),
(46, 46, '6 Sigma', 'Fr', 8, 1),
(47, 47, 'Finance', 'Fr', 8, 1),
(48, 48, 'Marketing et Ventes', 'Fr', 8, 1),
(49, 49, 'Autre', 'Fr', 8, 1),
(50, 50, 'Compilation de documents (Word, PowerPoint...)', 'Fr', 9, 1),
(51, 51, 'Saisie de données ', 'Fr', 9, 1),
(52, 52, 'Traductions', 'Fr', 9, 1),
(53, 53, 'Secrétariat ', 'Fr', 9, 1),
(54, 54, 'Autre', 'Fr', 9, 1),
(55, 55, 'Autre', 'Fr', 10, 1);
And my code is :
<link rel="stylesheet" href="jquery.treeview.css" />
<script type="text/javascript" src="jquery.min.js"></script>
<script src="jquery.cookie.js" type="text/javascript"></script>
<script src="jquery.treeview.js" type="text/javascript"></script>
<script type="text/javascript" src="demo.js"></script>
<?php
include('dbconnect.php');
function generate_menu($link)
{
$sql="SELECT `rowid`, `category_id`, `category_name`, `language`, `parent_id`, `level` FROM `category` where `parent_id`='0'";
$result=mysql_query($sql,$link);
if(mysql_num_rows($result)>0)
{
echo"<ul id='browser' class='filetree'>";
while($row=mysql_fetch_array($result))
{
echo"<li class='closed'><a href='#'>$row[2]</a>";
generate_submenu($row[1],$link);
echo"</li>";
}
echo"</ul>";
}
}
function generate_submenu($category_id,$link)
{
$sql="SELECT `rowid`, `category_id`, `category_name`, `language`, `parent_id`, `level` FROM `category` where `parent_id`='$category_id'";
$result=mysql_query($sql,$link);
if(mysql_num_rows($result)>0)
{
echo"<ul>";
while($row=mysql_fetch_array($result))
{
echo"<li><a href='#'>$row[2]</a></li>";
}
echo"</ul>";
}
}
generate_menu($link);
?>
<!-- <ul id="browser" class="filetree">
<li><span class="folder">Folder 1</span>
<ul>
<li><span class="file">Item 1.1</span></li>
</ul>
</li>
<li><span class="folder">Folder 2</span>
<ul>
<li><span class="folder">Subfolder 2.1</span>
<ul id="folder21">
<li><span class="file">File 2.1.1</span></li>
<li><span class="file">File 2.1.2</span></li>
</ul>
</li>
<li><span class="file">File 2.2</span></li>
</ul>
</li>
<li class="closed"><span class="folder">Folder 3 (closed at start)</span>
<ul>
<li><span class="file">File 3.1</span></li>
</ul>
</li>
<li><span class="file">File 4</span></li>
</ul>-->
Please someone help me on that.
vitana 0 Newbie Poster
may be better to use some free tool? For example dhtmlX tree
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.