我想将动态数据插入到我的前序遍历表中。我通过参考本教程使用rebuild_tree技术:http ://www.sitepoint.com/hierarchical-data-database-3/
这里我根据codeigniter的需要修改了代码。但是当我在 foreach 循环中调用函数rebuild_tree 时,它会显示致命错误,例如:
Fatal error: Maximum function nesting level of '100' reached, aborting! in /var/www/hr/system/database/drivers/mysql/mysql_driver.php on line 199 Call Stack: 0.0389 360600 1. {main}() /var/www/hr/index.php:0 0.0401 468096 2. require_once('/var/www/hr/system/core/CodeIgniter.php') /var/www/hr/index.php:240 0.0689 3798516 3. call_user_func_array() /var/www/hr/system/core/CodeIgniter.php:359 0.0689 3798588 4. Structure->add_structure() /var/www/hr/system/core/CodeIgniter.php:0 0.0689 3798632 5.
structure_model->rebuild_tree() /var/www/hr/application/controllers/test/structure.php:42 0.0701 3928356 6. structure_model->rebuild_tree() /var/www/hr/application/models/test/structure_model.php:35 0.0703 3931572 7. structure_model->rebuild_tree() /var/www/hr/application/models/test/structure_model.php:35 0.0705 3934788 8. structure_model->rebuild_tree() /var/www/hr/application/models/test/structure_model.php:35 0.0706 3938008 9.
CI_DB_driver->query() /var/www/hr/application/models/xome/structure_model.php:29 0.0848 4216988 97. CI_DB_driver->simple_query() /var/www/hr/system/database/DB_driver.php:299 0.0848 4216988 98. CI_DB_mysql_driver->_execute() /var/www/hr/system/database/DB_driver.php:453 0.0848 4216988 99. CI_DB_mysql_driver->_prep_query() /var/www/hr/system/database/drivers/mysql/mysql_driver.php:178
以下是我的代码:
function rebuild_tree($parent, $left) {
$resultArr = array();
$parent = $_GET['level'];
$left = $_GET['lft'];
$right = $_GET['rgt'];
$right = $left + 1;
$sql = 'SELECT * FROM subunit WHERE level="' . $parent . '";';
$query = $this->db->query($sql);
$data = $query->result();
foreach ($data as $datap) {
$resultArr['name'] = $datap->name;
$resultArr['level'] = $datap->level;
$right = $this->rebuild_tree($resultArr['level'], $right);
}
$sql = 'UPDATE subunit SET lft=' . $left . ', rgt=' . $right . ' WHERE name="' . $parent . '";';
$query = $this->db->query($sql);
return $right + 1;
}
有什么解决方案。谢谢你。