PHP HTML Unlimited Classification
$link = mysql_connect (' 127.0.0.1 ', ' root ', ' 520928 ') or Die (Mysql_error ());//Connect to database server
mysql_select_db (' test ');//Select Database
Mysql_set_charset (' UTF8 ');//Set character encoding
$sql = "SELECT * from Wxtree";//Query classification table
$result = mysql_query ($sql);
$tree = Array ();//Initialize an array
while ($row = Mysql_fetch_assoc ($result))
{
$tree [$row [' FID ']][$row [' id ']] = $row [' cat_name '];//creating a categorical array
}
Unset ($row);
Mysql_close ($link);//Close Database
Echo '-------------------------------------------'. "\ n";
Recursive functions
function for_category ($arr = Array (), $arr 2)
{
echo "
";
foreach ($arr as $k = $v)
{
if (Isset ($arr 2[$k]) && Is_array ($arr 2[$k]))
{
echo "
- $k $v ";
For_category ($arr 2[$k], $arr 2);
echo " ";
}
else{
echo "
- $k $v
";
}
}
echo "
";
}
For_category ($tree [0], $tree);
?>
This change how to add a variety of operations Ah, while loop words can be added, foreach how to add
Reply to discussion (solution)
Does the output of the entry go up on the line?
What to do, I just learned, while
while ($arr = Mysql_fetch_array ($res)) {?> > Edit > Delete
How to add output?
Didn't you add it to the top?
That's wrong, the program is using a Foreach loop, not while, and I'll
foreach ($arr as $value) {
echo "";
echo "";
}
?>
foreach ($arr as $value) {
echo "";
echo "";
}
?>
The one on the top has a wrong hit.
If you assoc out is only ID directly add $value Otherwise, you should know how to do
"; foreach ($arr as $k = + $v) {if (Isset ($arr 2[$k]) && Is_array ($arr 2[$k])) { echo "$k $v edit Delete "; For_category ($arr 2[$k], $arr 2); echo ""; } else{echo "
$k $v Popular groups ddd to edit delete" ; }} echo ""; } for_category ($tree [0], $tree);? >
"; foreach ($arr as $k = + $v) {if (Isset ($arr 2[$k]) && Is_array ($arr 2[$k])) { echo "
$k $v edit Delete "; For_category ($arr 2[$k], $arr 2); echo ""; } else{echo "
$k $v Popular groups ddd to edit delete" ; }} echo ""; } for_category ($tree [0], $tree);? >
The real effect is this, do an infinite class classification, using recursive call method, here the
You can't join a link between them.
echo "
$k $v Popular groups ddd to edit delete" ;
Double quotes in double quotes to escape!
echo "
$k $v Popular groups ddd to edit delete" ;