Home > Backend Development > PHP Tutorial > PHP嵌入html代码解决思路

PHP嵌入html代码解决思路

WBOY
Release: 2016-06-13 11:30:41
Original
840 people have browsed it

PHP嵌入html代码
$link   = mysql_connect( '127.0.0.1', 'root', '520928' ) or die( mysql_error() );//连接数据库服务器
          mysql_select_db( 'test' );//选择数据库
          mysql_set_charset( 'utf8' );//设置字符编码
 
             $sql = "SELECT * FROM wxtree";//查询分类表
          $result = mysql_query( $sql );
            $tree = array();//初始化一个数组
          while( $row  = mysql_fetch_assoc( $result ) )
                 {                   
                     $tree[$row['fid']][$row['id']]  = $row['cat_name'];//创建分类数组                                  
                 }
            unset( $row );
 
          mysql_close( $link );//关闭数据库
  
        
echo '-------------------------------------------' . "\n";
 
//递归函数
  
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 "
  • ";          
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template