PHP embedded html code

Source: Internet
Author: User
PHP embedded html code php html unlimited classification

$ Link = mysql_connect ('192. 0.0.1 ', 'root', '123') or die (mysql_error (); // connect to the database server
Mysql_select_db ('test'); // select a database
Mysql_set_charset ('utf8'); // sets the character encoding.

$ SQL = "SELECT * FROM wxtree"; // query a category table
$ Result = mysql_query ($ SQL );
$ Tree = array (); // Initialize an array
While ($ row = mysql_fetch_assoc ($ result ))
{
$ Tree [$ row ['fid'] [$ row ['id'] = $ row ['cat _ name']; // Create a category array
}
Unset ($ row );

Mysql_close ($ link); // closes the database


Echo '-----------------------------------------'. "\ n ";

// Recursive function

Function for_category ($ arr = array (), $ arr2)
{

Echo"
    ";
    Foreach ($ arr as $ k => $ v)
    {
    If (isset ($ arr2 [$ k]) & is_array ($ arr2 [$ k])
    {
    Echo"
  • $ K $ v ";
    For_category ($ arr2 [$ k], $ arr2 );
    Echo"
  • ";
    }
    Else {
    Echo"
  • $ K $ v
  • ";
    }
    }
    Echo"
";

}
For_category ($ tree [0], $ tree );

?>

How to add various operations in this change? you can add operations in the while loop, and add operations in the foreach loop.


Reply to discussion (solution)

When I output an entry, isn't it enough?

How to do it? I just learned, while

While ($ arr = mysql_fetch_array ($ res) {?>"> Edit"> Delete

How can I add an output?

Have you added the above?

That is wrong. The program uses the foreach loop instead of the while loop.

Foreach ($ arr as $ value ){
Echo"";
Echo"";
}
?>

Foreach ($ arr as $ value ){
Echo"";
Echo"";
}
?>
The one above is wrong.
If your assoc only has ID, add $ value directly. Otherwise, you should know how to do it.

 
 "; Foreach ($ arr as $ k => $ v) {if (isset ($ arr2 [$ k]) & is_array ($ arr2 [$ k]) {echo"
  • $ K $ v & nbsp edit and delete "; for_category ($ arr2 [$ k], $ arr2); echo"
  • ";} Else {echo"
  • $ K $ v modify and delete popular groups ddd & nbsp
  • ";}} Echo"";} For_category ($ tree [0], $ tree);?> "; Foreach ($ arr as $ k => $ v) {if (isset ($ arr2 [$ k]) & is_array ($ arr2 [$ k]) {echo"
  • $ K $ v & nbsp edit and delete "; for_category ($ arr2 [$ k], $ arr2); echo"
  • ";} Else {echo"
  • $ K $ v modify and delete popular groups ddd & nbsp
  • ";}} Echo"";} For_category ($ tree [0], $ tree);?>

    // The real effect is as follows: create an infinite classification and use recursive calling.
  • Cannot join links between them.

    Echo"

  • $ K $ v modify and delete popular groups ddd & nbsp
  • ";
    Double quotation marks must be escaped!
    Echo"
  • $ K $ v modify and delete popular groups ddd & nbsp
  • ";

    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.