From 661e298830a700272104783b049367bf505bff62 Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Wed, 9 Nov 2011 17:45:23 +0100 Subject: [PATCH] Pridan prototyp stromu kategorii pro budouci e-shop --- assistants/category-tree.inc.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 assistants/category-tree.inc.php 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);
-- 
2.30.2