From: Thomas Mudrunka Date: Wed, 9 Nov 2011 16:45:23 +0000 (+0100) Subject: Pridan prototyp stromu kategorii pro budouci e-shop X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=661e298830a700272104783b049367bf505bff62;p=mirrors%2FSokoMan.git Pridan prototyp stromu kategorii pro budouci e-shop --- diff --git a/assistants/category-tree.inc.php b/assistants/category-tree.inc.php new file mode 100644 index 0000000..f268ca7 --- /dev/null +++ b/assistants/category-tree.inc.php @@ -0,0 +1,19 @@ +
db->safe_query_fetch('SELECT * FROM category');
+
+function addleaf(&$tree, $levels, $category='') {
+	if(!count($levels)) return;
+	$current = array_shift($levels);
+	$category .= '/'.$current;
+	if(!isset($tree[$current])) $tree[$current] = array();
+	$tree[$current]['__PATH__'] = $category;
+	addleaf($tree[$current], $levels, $category);
+}
+
+$tree = array();
+foreach($result as $row) {
+	$row_parts = preg_split('/\//', $row['category_name']);
+	addleaf($tree, $row_parts);
+}
+
+print_r($tree);