A php second-level linkage with a database
Last Update:2014-05-06
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
}
?>