nested-sets

Build dynamic menu using Nested Sets

北城以北 提交于 2019-12-06 16:08:36
问题 I am trying to build a dynamic menu in my PHP CMS; the pages/categories are organized using the nested sets model. Full tree: root A B B1 B1.1 B1.2 B2 B2.1 B2.1 C C1 C2 C3 D I want to convert this result set to an unordererd list, which only displays a part of the tree. For example: If I click on B, I want to show only the following part of the list: A B B1 B2 C D Next, if I click on B1 I want the to show this list: A B B1 B1.1 B1.2 B2 C D etc. I use the following SQL query to get all nodes

How to insert data in the nested set model(MySQL);

喜欢而已 提交于 2019-12-06 12:12:05
问题 In the nested set model we have LEFT and Right columns the first time when the table is empty, what i need to insert to the RIGHT column, if i don't know how many children will i have LEFT 1 - forever RIGHT ? - what value goes here?? how to make it dynamic? not static. ps: using php 回答1: I'm assuming from your tags and title that you are looking for a solution that works with MySQL . Yes, you are right that unless you know the number of elements in advance the value for right needs to be

Nested Set indices & performance

北城余情 提交于 2019-12-06 11:37:08
I'm having some troubles understanding what indices to use on a Nested-Set model. The query is: SELECT `node`.`id`,(COUNT(parent.id) - 1) AS `depth`,`name` FROM `categories` AS `parent` INNER JOIN `categories` AS `node` ON (`node`.`lft` BETWEEN parent.lft AND parent.rgt) INNER JOIN `filebank_categories` ON (`node`.`id` = `filebank_categories`.`category_id` AND `filebank_categories`.`filebank_id` = 136) INNER JOIN `categories_names` ON (`categories_names`.`category_id` = `node`.`id` AND `categories_names`.`language_id` = 1) WHERE `node`.`system_id` = parent.system_id GROUP BY node.id ORDER BY

Generate JSON from nested sets (perl, sql, jquery)

僤鯓⒐⒋嵵緔 提交于 2019-12-06 11:24:41
问题 I have content pages in the database (using nested sets) and I need to show it by jQuery jsTree plugin. It's need to return JSON with data like this: [ { data: 'node1Title', children: [ { data: 'subNode1Title', children: [...] }, { data: 'subNode2Title', children: [...] } ] }, { data: 'node2Title', children: [...] } ] What I need for do it? I can transform an array of hashes to JSON but I don't understand how to generate an array. Sample data: **'pages'table** id parent_id level lkey rkey

PHP: Sort an array

 ̄綄美尐妖づ 提交于 2019-12-05 16:09:16
I've got an array with data from a MySQL table in nested set model I'd like to get sorted, not only alphabetical but also with the child nodes directly after the parent node. Example - array to be sorted (before the sorting): Array ( [0] => Array ( [id] => 1 [name] => Kompetenser [parent] => 0 [depth] => 0 ) [1] => Array ( [id] => 2 [name] => Administration [parent] => 1 [depth] => 1 ) [2] => Array ( [id] => 11 [name] => Organisation [parent] => 2 [depth] => 2 ) [3] => Array ( [id] => 4 [name] => Arbetsledning [parent] => 2 [depth] => 2 ) [4] => Array ( [id] => 17 [name] => Planering [parent]

Nested sets, php array and transformation

雨燕双飞 提交于 2019-12-05 12:40:20
I need to transform my nested sets structure (mysql) into json for this spacetree 1) http://blog.thejit.org/wp-content/jit-1.0a/examples/spacetree.html I found this function to create an array from nested sets: 2) http://semlabs.co.uk/journal/converting-nested-set-model-data-in-to-multi-dimensional-arrays-in-php I can also convert php array into json with PHP function json_encode My problem: the function nestify (from second link) gives me not exactly that i need. I need something like this: http://pastebin.com/m68752352 Can you help me change the function "nestify" so it gives me the correct

get all products of category and child categories (rails, awesome_nested_set)

跟風遠走 提交于 2019-12-04 21:57:22
问题 having an e-commerce application under development i am trying to get my head around the following problem: I have my categories realized through the awesome_nested_set plugin. If I list my articles through selecting one category everything works fine, but for some links I want to show all the products of one category and the products of its child categories. here is the controller code that works fine with only one category: # products_controller.rb def index if params[:category] @category =

Build dynamic menu using Nested Sets

喜你入骨 提交于 2019-12-04 20:53:36
I am trying to build a dynamic menu in my PHP CMS; the pages/categories are organized using the nested sets model. Full tree: root A B B1 B1.1 B1.2 B2 B2.1 B2.1 C C1 C2 C3 D I want to convert this result set to an unordererd list, which only displays a part of the tree. For example: If I click on B, I want to show only the following part of the list: A B B1 B2 C D Next, if I click on B1 I want the to show this list: A B B1 B1.1 B1.2 B2 C D etc. I use the following SQL query to get all nodes from the (mysql) database: SELECT node.id, node.lft, node.rgt, node.name, GROUP_CONCAT(parent.name ORDER

Generate JSON from nested sets (perl, sql, jquery)

雨燕双飞 提交于 2019-12-04 17:44:19
I have content pages in the database (using nested sets) and I need to show it by jQuery jsTree plugin. It's need to return JSON with data like this: [ { data: 'node1Title', children: [ { data: 'subNode1Title', children: [...] }, { data: 'subNode2Title', children: [...] } ] }, { data: 'node2Title', children: [...] } ] What I need for do it? I can transform an array of hashes to JSON but I don't understand how to generate an array. Sample data: **'pages'table** id parent_id level lkey rkey name 1 0 1 1 14 index 2 1 2 2 7 info 3 1 2 8 13 test 4 2 3 3 4 about 5 2 3 5 6 help 6 3 3 9 10 test1 7 3 3

Finding breadcrumbs for nested sets

走远了吗. 提交于 2019-12-04 13:16:46
问题 I'm using nested sets (aka modified preorder tree traversal) to store a list of groups, and I'm trying to find a quick way to generate breadcrumbs (as a string, not a table) for ALL of the groups at once. My data is also stored using the adjacency list model (there are triggers to keep the two in sync). So for example: ID Name ParentId Left Right 0 Node A 0 1 12 1 Node B 0 2 5 2 Node C 1 3 4 3 Node D 0 6 11 4 Node E 3 7 8 5 Node F 4 9 9 Which represents the tree: Node A Node B Node C Node D