A php second-level linkage with a database. ****************************************: Php level-2 linkage menu ********************** author: * Email: ***/*********************************** ********
*************
*************************
* 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, 0, 2) = "[""){
$ SMenu = "[". $ sMenu;
} Else {
$ SMenu = preg_replace ("/[{3,}/is", "[[1", $ sMenu); // Match
: Php level-2 linkage menu ********************** author: * Email: njj@nuc.edu.cn ***...