Multi Level Category Menu PHP MySQL Source Code

Posted on

Multi Stage Class Menu PHP MySQL Provide Code will make a multi-level stacked class menu using PHP and MySQL database, by contacting a recursive carry out, we’re in a position to current limitless diploma of groups and subcategories on the fly.

Multi Stage Class Menu PHP MySQL Provide Code Database Building :

  • category_id : Predominant key for the desk.
  • category_name : Determine of the category(stage) that may be displayed throughout the drop down.
  • parent_id : It is the mom or father to corresponding category_id. For root class parent_id is 0.

Multi Stage Class Menu PHP MySQL Provide Code

//Title Carry out

$cat_query = “SELECT category_id, category_name, parent_id FROM class ORDER BY parent_id, category_id”;

//Execute the above mysql query an apply mysql_fetch_array() logic to get a multidimensional array.

$outcomes = manual_query($cat_query);

foreach ($outcomes as $consequence) {

$class[‘categories’][$result[‘category_id’]] = $consequence;

$class[‘parent_cats’][$result[‘parent_id’]][] = $consequence[‘category_id’];

}

$data[‘category’] = buildCategory(0, $class);

//Carry out Code

carry out buildCategory($mom or father, $class) {

$html = “”;

if (isset($class[‘parent_cats’][$parent])) {

$html .= “

n”;

}

return $html;

}

?>

Provide iwantsourcecodes.com