Showing posts with label Multi level category. Show all posts
Showing posts with label Multi level category. Show all posts

Saturday, 18 April 2015

Build Multi Level Category Using PHP & Mysql


In this tutorial we will create a multi-level nested category menu using PHP and mysql, by calling a recursive function, we can display infinite level of categories and subcategories on the fly, for a drop down box that might look like the following image.


Build Multi Level Category Using PHP & Mysql

Following is the PHP code snippet to build multi-level category using mysql :

Database Structure : 

You will need to create a table 'category' with 3 columns as follows : 

category_id : Primary key for the table.
category_name : Name of the category(level) that will be displayed in the drop down.
parent_id : It is the parent to corresponding category_id. For root category parent_id is 0.