PHP database tree traversal method. The code is as follows :? Phpsession_start (); define (P_S, PATH_SEPARATOR); define (ROOT,.); set_include_path (ROOT. P_S.Zend.P_S.ROOT.get_include_pat code is as follows:
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 the ZEND Framework
Require_once ROOT. 'zend/Loader. php ';
Require_once 'usercheck. php'; // load the access permission
Zend_Loader: loadFile ('function. class. php', $ dirs = 'class/', $ once = false); // load the function
Zend_Loader: loadClass ('zend _ db'); // load the database class
Zend_Loader: loadClass ('zend _ Config_Ini '); // load the configuration class
$ Config = new Zend_Config_Ini ('config. php', 'total'); // Create a configuration object
$ Db = Zend_Db: factory ($ config-> db-> adapter, $ config-> db-> config-> toArray (); // create a database object
$ Select = $ db-> select ();
$ Select-> from ('sclass ', 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-level nodes of nodeid
$ Rs = $ db-> fetchAll ($ recordset );
Foreach ($ rs as $ rss ){
If (! $ Rss)
Return; // a leaf node is returned directly.
Else {
For ($ I = 0; $ I <4 * $ stept; $ I ++ ){
Echo "";
}
Echo ''. $ rss ['lsh']. $ rss ['name']."
";
Visit ($ rss ['lsh'], $ stept + 1 );
}
}
}
?>
The pipeline code is 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...