php递归(过程.更易懂)

很早很早很早写的一个递归,还是用过程写的,有着纪念的意义啊.....

<?php
mysql_connect("localhost","root","2765237");
mysql_select_db("phpbbs");
mysql_set_charset("gbk");
    $sql="select * from `bbs_class` where lv_class_id=0";
    $query=mysql_query($sql);
    while ($rs=mysql_fetch_array($query))
    {
        $result[]=$rs;
    }<!--more-->
    function aaa($num)
    {
        mysql_connect("localhost","root","2765237");
        mysql_select_db("phpbbs");
        mysql_set_charset("gbk");
        $sql="select * from `bbs_class` where lv_class_id='".$num."'";
        $query=mysql_query($sql);
        while ($rs=mysql_fetch_array($query))
        {
            $result[]=$rs;
        }
        $nums=mysql_num_rows($query);
        if($nums==0)
        {
            return false;
        }
        foreach ($result as $val)
        {
            echo $val['class_name']."<br>";
            aaa($val['id']);
        }
    }
    foreach ($result as $val)
    {
        echo $val['class_name']."<br>";
        aaa($val['id']);    
    }
?>

Leave a Reply

(will not be published)