<?php 
include_once("connect.php");
include_once("functions.php");

?>

<title>Menu</title>

<link rel="stylesheet" href="style.css" type="text/css" media="all">

<div class="container">



	<?php

	$sql = "SELECT id, label, link, parent FROM menus ORDER BY id,parent, sort, label";

	$result = mysqli_query($conn, $sql) or die("database error:". mysqli_error($conn));

	// Create an array to conatin a list of items and parents

	$menus = array(

		'items' => array(),

		'parents' => array()

	);

	// Builds the array lists with data from the SQL result

	while ($items = mysqli_fetch_assoc($result)) {

		// Create current menus item id into array

		$menus['items'][$items['id']] = $items;

		// Creates list of all items with children

		$menus['parents'][$items['parent']][] = $items['id'];

	}

	// Print all tree view menus 

	echo createTreeView(0, $menus);

	/*

	?>		

	

	<div style="margin:50px 0px 0px 0px;">

		<a class="btn btn-default read-more" style="background:#3399ff;color:white" href="http://www.phpzag.com/how-to-create-dynamic-tree-view-menu-in-php" title="How to Create Dynamic Tree View Menu in PHP">Back to Tutorial</a>			

	</div>	

	*/

	?>

</div>

