PHP database tree traversal method _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.