Php second-level linkage _ PHP Tutorial for a database

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

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.