📜 ⬆️ ⬇️

The task of displaying trees in MySql. How to display on stored procedures

Good day.

I really wanted to raise the issue of tree structures in MySql. Specifically, about sampling and data storage ...
Oracle users and PostgresSQL live well, these databases have built-in tools for retrieving recurrent data (see Hierarchical (recursive) queries ).
Mysql users have to work with what is, that is, work on the client side.
Since this topic has been raised more than once, I will try to talk about a specific task and how to solve it.

Task


There is a project in php, it has a double structure implemented in the table mysql catalog (id int NOT NULL, pid int NOT NULL, ...)
pid is the id of the parent. That is, the data is stored in one table, each cell refers to the parent. Thus the whole tree is formed.
Naturally, the table stores a bunch of related data, the description of which I will omit, since they will not affect the essence of the task, but will only interfere.

An example of such data storage:
CREATE TABLE catalog ( id INT NOT NULL PRIMARY , pid INT NOT NULL , someData text NOT NULL ) comment = " "; * This source code was highlighted with Source Code Highlighter .
  1. CREATE TABLE catalog ( id INT NOT NULL PRIMARY , pid INT NOT NULL , someData text NOT NULL ) comment = " "; * This source code was highlighted with Source Code Highlighter .
  2. CREATE TABLE catalog ( id INT NOT NULL PRIMARY , pid INT NOT NULL , someData text NOT NULL ) comment = " "; * This source code was highlighted with Source Code Highlighter .
  3. CREATE TABLE catalog ( id INT NOT NULL PRIMARY , pid INT NOT NULL , someData text NOT NULL ) comment = " "; * This source code was highlighted with Source Code Highlighter .
  4. CREATE TABLE catalog ( id INT NOT NULL PRIMARY , pid INT NOT NULL , someData text NOT NULL ) comment = " "; * This source code was highlighted with Source Code Highlighter .
  5. CREATE TABLE catalog ( id INT NOT NULL PRIMARY , pid INT NOT NULL , someData text NOT NULL ) comment = " "; * This source code was highlighted with Source Code Highlighter .
CREATE TABLE catalog ( id INT NOT NULL PRIMARY , pid INT NOT NULL , someData text NOT NULL ) comment = " "; * This source code was highlighted with Source Code Highlighter .
idpidsomeData
one0Catalog
2oneBook 1
3oneBook 2
four3Chapter 1
five3Chapter 2
63Chapter 3


')
The entire tree is sampled recursively on the client side. The total base of 500MB, and will continue to grow. Since there are many branches and nodes, the total number of requests to the database currently ranges from 300 to 1000.

As a result of recurrent sampling, an array of data is formed (for some reason, also of a recurrent type), which is given to the template engine.
The task is to optimize the sample so that it pulls out the necessary data in one query (well, or two or three, but not so that there are so many ...)

Solution



The task as a whole is trivial. She repeatedly decided. Additional data are entered that is used to restrict the selection from the table. The whole question boils down to what kind of additional field (s). One way or another, additional data leads to redundancy, which means overhead for maintaining the correctness of data.

In publications, the most common solution is with an additional field of the varchar type, in which id-names are stored, separated by a special character. This field is used for sorting and limiting by something like% ...%.

In general, the solution is very good, but has its drawbacks:
  1. natural restriction on hierarchy nesting.
  2. overhead and difficulty supporting this field. (in my case, if you write a script involved in supporting this field, then it will just hang on timeout, which means you need to do these actions in cron)
  3. a serious load on the network, which is the basis for setting the task, the load is not where it has gone, it is just in the background, and the server still slows down.
  4. in case of transferring tree nodes, update this field data.


As a result, we get a rather difficult and complicated decision. There was no time for its implementation as always.

To solve all the problems outlined above, you need to act differently. First, it is better to do the formation of additional data where this data is located, that is, on the side of the database. Secondly, supporting additional data is an overhead, so it’s best to update it every time.

This concept is implemented as follows: a simple procedure is written that would form the data for the tmp__index timestamp, performing a recurrent tree walk.
Here is the real procedure code:

DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  1. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  2. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  3. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  4. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  5. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  6. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  7. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  8. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  9. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  10. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  11. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  12. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  13. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  14. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  15. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  16. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  17. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  18. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  19. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  20. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  21. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  22. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  23. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  24. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  25. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  26. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  27. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  28. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  29. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  30. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  31. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  32. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  33. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  34. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  35. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  36. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  37. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  38. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  39. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  40. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  41. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  42. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  43. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  44. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  45. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  46. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  47. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  48. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  49. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  50. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  51. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  52. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  53. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  54. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
  55. DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .
DELIMITER $$ DROP PROCEDURE IF EXISTS `getIndexToTmpTable`$$ /** main_id - search_id - zlevel - , , - -1 - sublevel - , - 1 */ CREATE PROCEDURE `getIndexToTmpTable` ( in main_id INT , in search_id INT , in zlevel INT , in sublevel INT ) BEGIN DECLARE done INT DEFAULT 0; DECLARE catalog_id INT ; DECLARE catalog_pid INT ; DECLARE cur1 CURSOR FOR select id,pid from catalog where pid=search_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; IF sublevel<=1 THEN /** */ IF zlevel<=0 THEN /** */ SET max_sp_recursion_depth= 15; ELSE SET max_sp_recursion_depth= zlevel+1; END IF ; END IF ; OPEN cur1; IF main_id = search_id THEN /** , */ insert into tmp__index set id = main_id, pid =( select pid from catalog where id=main_id limit 1), rid =main_id, level = sublevel-1; END IF ; /** */ REPEAT FETCH cur1 INTO catalog_id,catalog_pid; IF NOT done THEN /** */ insert into tmp__index set id = catalog_id, pid = catalog_pid, rid = main_id, level = sublevel; /** */ call getIndexToTmpTable(main_id,catalog_id,zlevel,sublevel+1); END IF ; UNTIL done END REPEAT; CLOSE cur1; END $$ DELIMITER ; * This source code was highlighted with Source Code Highlighter .

The start of the procedure is preceded by the creation of a temporary table, and then a simple select is ripped out the necessary data.

CREATE TEMPORARY TABLE tmp__index(id int ,pid int ,rid int ); call getIndexToTmpTable(<id_>,<id_>,1,1); select c.* from catalog as c join tmp__index as t on t.rid=c.id * This source code was highlighted with Source Code Highlighter .
  1. CREATE TEMPORARY TABLE tmp__index(id int ,pid int ,rid int ); call getIndexToTmpTable(<id_>,<id_>,1,1); select c.* from catalog as c join tmp__index as t on t.rid=c.id * This source code was highlighted with Source Code Highlighter .
  2. CREATE TEMPORARY TABLE tmp__index(id int ,pid int ,rid int ); call getIndexToTmpTable(<id_>,<id_>,1,1); select c.* from catalog as c join tmp__index as t on t.rid=c.id * This source code was highlighted with Source Code Highlighter .
  3. CREATE TEMPORARY TABLE tmp__index(id int ,pid int ,rid int ); call getIndexToTmpTable(<id_>,<id_>,1,1); select c.* from catalog as c join tmp__index as t on t.rid=c.id * This source code was highlighted with Source Code Highlighter .
CREATE TEMPORARY TABLE tmp__index(id int ,pid int ,rid int ); call getIndexToTmpTable(<id_>,<id_>,1,1); select c.* from catalog as c join tmp__index as t on t.rid=c.id * This source code was highlighted with Source Code Highlighter .

Let's stop for a minute and think about what we have done and how good it is:
  1. we do all 3rd queries to the database
  2. got rid of the problems associated with the support of the additional field, since everything is dynamically generated
  3. this procedure cannot loop, mysql limits the recursion depth
  4. we can control ourselves how deeply we need to go around the tree (that is, to what level)
  5. we know everything about each element, down to what level it is
  6. secondary execution of the procedure on the same data can be eliminated using the local cache of the query result.

Honestly, I was very surprised that such a functionality is so easily implemented by the database. However, we go further, the task is not completely solved. Now the question arises - what to do with this array. There are only two options:
  1. rewrite all templates in a new way.
  2. make a tree structure from linear.

I believe that if there is a possibility, then it is better to refactor templates so that they understand the linear data structure. This is the most good way. But unfortunately in my case, it is easier and faster to make a wood-like structure, and not to cringe the entire project ...

So I did this: formed a caracas tree based on the links, sequentially placing a reference to the child element in the parent element. After forming the skeleton of a tree, I walked through it recurrently and created a tree with real data.


The figure shows the kind of frame I get. I schematically indicated the name of the field there, but in reality there are only identifiers stored in the form $ id => array (...), where $ id is the element identifier, and the array contains a set of links to the root elements of the array. It is important to understand that records with the same name refer to the same memory location. The total amount of data stored in the memory is the number of elements + overhead costs of storing an array of links.

Here is the conversion code, it's in the inside of the class. Please do not judge strictly, it was written quickly, from under the lash:

protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  1. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  2. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  3. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  4. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  5. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  6. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  7. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  8. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  9. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  10. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  11. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  12. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  13. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  14. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  15. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  16. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  17. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  18. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  19. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  20. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  21. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  22. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  23. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  24. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  25. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  26. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  27. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  28. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  29. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  30. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  31. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  32. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  33. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  34. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  35. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  36. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  37. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  38. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  39. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  40. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  41. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  42. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  43. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  44. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  45. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  46. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  47. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  48. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  49. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  50. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  51. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  52. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  53. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
  54. protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .
protected $_idToData = null ; protected $_dataArray = null ; /** * * , * $_idToData, $_data * * @param array& $curItemFrom * @param array& $curItemTo */ protected function _recGenTreeResult(array&$curItemFrom,array&$curItemTo) { foreach ($curItemFrom as $id=>&$list) { if (!isset($ this ->_idToData[$id]) || !isset($ this ->_dataArray[ $ this ->_idToData[$id] ])) throw new Exception( 'recursion build error!' ); $curItemTo[] = $ this ->_dataArray[ $ this ->_idToData[$id] ]; $i = count($curItemTo)-1; if (count($list)) { $curItemTo[$i][ 'dir' ] = array(); $ this ->_recGenTreeResult(&$list,&$curItemTo[$i][ 'dir' ]); } } } function listToTree($dataArray) { $ this ->_dataArray = &$dataArray; $ this ->_idToData = array(); $parentList = array(); $rootIds = array(); // // id-> num data foreach ($ this ->_dataArray as $k=>$d) $ this ->_idToData[$d[ 'id' ]] = $k; foreach ($ this ->_dataArray as $k=>$d) { // $pid=>array($id, ...), $parentList[$d[ 'pid' ]][$d[ 'id' ]]= array(); // , ... if (isset($ this ->_idToData[$d[ 'pid' ]])) { // if (isset($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]])) if (empty($parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ])) $parentList[ $ this ->_dataArray[ $ this ->_idToData[$d[ 'pid' ]] ][ 'pid' ]][ $d[ 'pid' ] ] = &$parentList[$d[ 'pid' ]]; } else $rootIds [$d[ 'pid' ] ] = true ; } $result = array(); foreach (array_keys($rootIds) as $pid) $ this ->_recGenTreeResult(&$parentList[$pid],&$result); return $result; } * This source code was highlighted with Source Code Highlighter .

In the end, we got quite a workable thing. In the case of a large base and the depth of recursion, this solution can also be bad. specifically can be bad to mySql server. I would solve this problem by introducing a caching table (permanent), which would store the results of the descent from the beginning of a certain element, and copy them into a temporary table. That is, the classic recursion cache would work, only in SQL. This is close to dynamic programming techniques. Maybe I’ll ever realize it if the local cache is not enough for stable operation. Although I think that's enough ...



links to what to read:


UPD The article is written by Nikolai Punin (nicolay.punin@gmail.com), who, unfortunately, does not yet have an invite.

Source: https://habr.com/ru/post/72700/


All Articles