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";