A php second-level linkage with a database

Source: Internet
Author: User
? Php /************************************** * ************** efficacy: php level-2 linkage menu ********************** author: * Email: njj@nuc.edu.cn ** /*************************************** ****
* ********* Function: php second-level linkage menu *************
*************************
* Email: njj@nuc.edu.cn **************
* ******** Date: 2004/10/02 ******************
* ********* Reserve the copyright information when you reprint it **************
**************************************** ***/

Require_once ('Db. inc. php'); // database connection
$ Db = new hq_online;
$ Db1 = new hq_online;
$ Db-> query ('select * from news_bclass order by id desc ');
$ FMenu = '';
$ FValue = '';
While ($ db-> next_record ()){
$ FMenu. = '\'. $ db-> Record ['bname']. '\', ';
$ FValue. = '\'. $ db-> Record ['id']. '\', ';

}
$ FMenu = substr ($ fMenu, 0, (strlen ($ fMenu)-1 ));
$ FMenu = '['. $ fMenu. ']'; // ***************************** get var fMenu
$ FValue = substr ($ fValue, 0, (strlen ($ fValue)-1 ));
$ FValue = '['. $ fValue. ']'; // ***************************** get var fValue

// Obtain ***************************** var sMenu.
$ Db-> query ('select * from news_bclass order by id desc ');
While ($ db-> next_record ()){
$ Parentid = $ db-> Record ['id'];
$ Db1-> query ('select * from news_sclass where parentid = '$ parentid 'Order by parentid desc ');
While ($ db1-> next_record ()){
$ Num = $ db1-> num_rows ();
$ I;
$ SMenu. = '\ ''. $ db1-> Record ['sname'].' \ ',';
If ($ I = $ num ){
$ SMenu = '['. $ sMenu. '], [';
$ I = 0;
}
}
}
$ SMenu. = ']';
$ SMenu = str_replace ('\',] ',' \ ']', $ sMenu );
$ SMenu = str_replace (', []', ']', $ sMenu );
If (substr ($ sMenu,) = '[\''){
$ SMenu = '['. $ sMenu;
} Else {
$ SMenu = preg_replace ('/\ [{3,}/is',' [\ 1', $ sMenu); // Match
}

// Obtain ***************************** var sValue
$ Db-> query ('select * from news_bclass order by id desc ');
While ($ db-> next_record ()){
$ Parentid = $ db-> Record ['id'];
$ Db1-> query ('select * from news_sclass where parentid = '$ parentid 'Order by parentid desc ');
While ($ db1-> next_record ()){
$ Nums = $ db1-> num_rows ();
$ J;
$ SValue. = '\ ''. $ db1-> Record ['id'].' \ ',';
If ($ j = $ nums ){
$ SValue = '['. $ sValue. '], [';
$ J = 0;
}
}
}
$ SValue. = ']';
$ SValue = str_replace ('\',] ',' \ ']', $ sValue );
$ SValue = str_replace (', []', ']', $ sValue );
If (substr ($ sValue, 0, 2) = '[\''){
$ SValue = '['. $ sValue;
} Else {
$ SValue = preg_replace ('/\ [{3,}/is',' [\ 1', $ sValue); // Match
}

?>

Related Article

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.