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

PHP嵌入html代码解决思路

WBOY
WBOYOriginal
2016-06-13 11:30:41834browse

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 "
  • ";          
Statement:
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