PHP Embed HTML code

Source: Internet
Author: User
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
  • " ;
  • 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.