MySqlでツリーを表示するタスク。 ストアドプロシージャの表示方法

良い一日。



私は本当にMySqlでツリー構造の問題を提起したかった。 具体的には、サンプルとデータストレージについて...

OracleとPostgresSQLのユーザーの寿命は長く、これらのデータベースには、再帰データを選択するための組み込みツールがあります( 階層(再帰)クエリを参照 )。

Mysqlユーザーは、クライアント側で作業する必要があります。

このトピックは一度取り上げられていないため、特定の問題とその解決方法についてお話します。



挑戦する



PHPにプロジェクトがあり、mysqlカタログテーブルに実装された2つの構造を持っています(id int NOT NULL、pid int NOT NULL、...)

pidは親のIDです。 つまり、データは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 .



  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 .



id pid someData
1 0 カタログ
2 1 ブック1
3 1 ブック2
4 3 第1章
5 3 第2章
6 3 第3章






ツリー全体がクライアント側で再帰的にサンプリングされます。 合計ベースサイズは500Mbであり、成長を続けるだけです。 多くのブランチとノードがあるため、データベースへのクエリの総数は現在300から1000の範囲です。



再帰的サンプリングの結果として、データの配列が(何らかの理由で、再帰的形式でも)形成され、テンプレートエンジンに渡されて消費されます。

タスクは、選択を最適化して、必要なデータを1つのリクエストで抽出することです(まあ、2つまたは3つですが、それほど多くはありません...)



ソリューションオプション





全体としてのタスクは簡単です。 彼女は繰り返し決定されました。 テーブルからの選択を制限するために使用される追加データが入力されます。 全体の質問は、それがどのような追加フィールドであるかにかかっています。 何らかの方法でデータを追加すると冗長性が生じます。これは、データの正確性を維持するためのオーバーヘッドを意味します。



出版物で最も一般的な解決策は、varchar型の追加フィールドです。このフィールドでは、idタグが特殊文字で区切られたテキストとともに保存されます。 このフィールドはソートされ、%...%のようなものに制限されます。



一般に、ソリューションは非常に優れていますが、欠点があります。

  1. 階層のネストに関する自然な制限。
  2. このフィールドを維持するオーバーヘッドと困難。 (私の場合、このフィールドをサポートするスクリプトを記述すると、タイムアウトによってハングするだけです。つまり、cronでこれらのアクションを実行する必要があります)
  3. ネットワーク上の深刻な負荷。これが問題の声明の根拠であり、負荷がなくなることはなく、バックグラウンドにあるだけで、サーバーはとにかく遅くなります。
  4. ツリーノードの転送の場合、このフィールドのデータを更新する必要があります。




その結果、やや困難な決定を下すことになります。 いつものように、実装する時間はありませんでした。



上記のすべての問題を解決するには、異なる行動を取る必要があります。 第一に、追加データの形成は、このデータが配置されている場所、つまりデータベース側で行うのが最適です。 第二に、追加データのサポートはオーバーヘッド操作であるため、毎回更新することをお勧めします。



この概念は次のように実装されます。tmp__index一時プレートのデータを生成する単純な手順が記述され、再帰的なツリートラバースが行われます。

実際の手順コードは次のとおりです。



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 .







手順の開始前に一時的なプレートが作成され、その後、単純な選択により必要なデータが引き裂かれます。



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 .







少し立ち止まって、私たちがやったこととそれがどれほど良いかについて考えましょう:

  1. データベースに対して3つのクエリをすべて実行します
  2. すべてが動的に生成されるため、追加フィールドのサポートに関連する問題を取り除きました
  3. このプロシージャはループできません。mysqlは再帰の深さを制限します
  4. ツリーをどの程度深く(つまり、どのレベルまで)巡回する必要があるかを制御できます。
  5. すべての要素について、そのレベルまですべてを知っています
  6. クエリ結果のローカルキャッシュを使用して、同じデータに対するプロシージャの2次実行を排除できます。


正直なところ、このような機能がデータベースツールによって非常に簡単に実装されていることに非常に驚きました。 ただし、さらに先に進むと、タスクは完全には解決されていません。 ここで疑問が生じます-この配列をどうするか。 次の2つのオプションのみがあります。

  1. すべてのテンプレートを新しい方法で書き換えます。
  2. ツリー構造を線形にします。


可能であれば、線形データ構造を理解できるようにテンプレートをリファクタリングすることをお勧めします。 これが最も確実な方法です。 しかし残念なことに、私の場合は、プロジェクト全体を台無しにするのではなく、木構造を作成する方が簡単で迅速です...



そこで私はこれを行いました。リンクに基づいてツリーカラカスを形成し、親要素内の子要素へのリンクを順番に配置しました。 ツリーフレームが形成された後、再帰的に調べて、実際のデータでツリーを作成しました。





図は、受信したフレームのビューを示しています。 そこにフィールドの名前を模式的に示しましたが、実際には識別子のみが$ id => array(...)の形式で格納されます。ここで、$ idは要素の識別子であり、配列には配列のルート要素へのリンクのセットが含まれます。 同じ名前のレコードは同じメモリ位置を参照することを理解することが重要です。 メモリに保存されるデータの合計量は、要素の数+リンクの配列を保存するオーバーヘッドです。



変換コードは次のとおりです。クラス内にあります。 厳密に判断しないでください、それはスティックの下からすぐに書かれました:



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 .







その結果、かなり実用的なものが得られました。 基数が大きく、再帰の深さが大きい場合、この解決策も悪い可能性があります。 具体的には、mySqlサーバーにとっては悪いことです。 特定の要素の先頭からの降下の結果を保存し、それらを一時テーブルにコピーするキャッシュテーブル(定数)を導入して、この問題を解決します。 つまり、従来の再帰キャッシュはSQLでのみ取得されます。 これは、動的プログラミング手法に近いものです。 いつか、ローカルキャッシュが安定した運用に十分でない場合に気付くでしょう。 私はそれで十分だと思いますが...






読むべきものへのリンク:





UPDこの記事はニコライ・プニン(nicolay.punin@gmail.com)によって書かれましたが、残念ながらまだ招待されていません。



All Articles