PHP 数据库树的遍历方法
代码如下:
复制代码 代码如下:
session_start();
define ('P_S', PATH_SEPARATOR);
define ('ROOT', "./");
set_include_path(ROOT .P_S .'Zend' .P_S .ROOT.get_include_path());
//加载ZEND 框架
require_once ROOT.'Zend/Loader.php';
require_once 'usercheck.php';//加载访问权限
Zend_Loader::loadFile('function.class.php', $dirs='class/', $once=false);//加载函数
Zend_Loader::loadClass('Zend_Db');//加载数据库类
Zend_Loader::loadClass('Zend_Config_Ini');//加载配置类
$config = new Zend_Config_Ini('config.php', 'general');//创建配置对象
$db = Zend_Db::factory($config->db->adapter,$config->db->config->toArray());//创建数据库对象
$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; //搜索nodeid的所有下层节点
$rs=$db->fetchAll($recordset);
foreach($rs as $rss){
if(!$rss)
return; //已经是叶子节点,直接返回
else{
for ($i=0;$iecho " ";
}
echo ' '.$rss['lsh'].$rss['name']."
";
Visit($rss['lsh'],$stept+1);
}
}
}
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
