Home  >  Article  >  Backend Development  >  PHP database tree traversal method_PHP tutorial

PHP database tree traversal method_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:48:161054browse

The code is as follows:

Copy code The code is as follows:

session_start();
define ('P_S', PATH_SEPARATOR);
define ('ROOT', "./");
set_include_path(ROOT .P_S .'Zend' .P_S .ROOT.get_include_path());
// Load ZEND framework
require_once ROOT.'Zend/Loader.php';
require_once 'usercheck.php';//Load access rights
Zend_Loader::loadFile('function.class.php', $dirs ='class/', $once=false);//Loading function
Zend_Loader::loadClass('Zend_Db');//Loading database class
Zend_Loader::loadClass('Zend_Config_Ini');//Loading Configuration class
$config = new Zend_Config_Ini('config.php', 'general');//Create configuration object
$db = Zend_Db::factory($config->db->adapter,$ config->db->config->toArray());//Create database object
$select=$db->select();
$select->from('ResClass' ,array('lsh','name'));
$select->where('steps = 1');
$rs=$db->fetchAll($select);
foreach ($rs as $res){
echo ' '.$res['lsh'].$res['name']."
";
Visit($res['lsh' ],1);
}
function Visit($nodeid,$stept){
global $db;
$recordset = "SELECT lsh,name FROM ResClass WHERE parent=".$nodeid; //Search all lower nodes of nodeid
$rs=$db->fetchAll($recordset);
foreach($rs as $rss){
if(!$rss)
return ; //Already a leaf node, return directly to
else{
for ($i=0;$i<4*$stept;$i++){
echo " ";
}
echo ' '.$rss['lsh'].$rss['name']."
";
Visit($rss['lsh'],$stept+1);
}
}
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319793.htmlTechArticleThe code is as follows: Copy the code as follows: ?php session_start(); define ('P_S', PATH_SEPARATOR); define ('ROOT', "./"); set_include_path(ROOT .P_S .'Zend' .P_S .ROOT.get_include_pat...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn