dst2017 2011-04-07 19:50
浏览 12
已采纳

如何使用他们的类别循环子类别?

EDIT: ok let me be a bit more clear i have a html file name file.html it is like this:

{category} {sybcategory}

and i have a index file which is like this:

class template { var $page;

function add_file($file){
    $this->page = file_get_contents($file);
    return $this->page;
}

function vars($array)
{
    foreach($array as $key => $value)
    {
        $this->page = str_replace('{'.$key.'}', $value, $this->page);
    }
    echo $this->page;
}

}

$template = new template();

$template->add_file('file.html');

$template->file_vars(array('category' => $row_cat['title'], 'subcategory' => $row_subcat['title']));

now, this only outputs the title and the subcategory only once how do i loop that and i have not added the mysql query here because i don't wanna waste your more time please if you know how to do it then let me know.

  • 写回答

2条回答 默认 最新

  • dongzhui2636 2011-04-07 20:01
    关注

    Here you go:

    $cats = array();
    
    while (mysql_fetch_assoc($mycategory))
    {    
        $cats[$cat_title] = array();
    
        while (mysql_fetch_assoc($mysubcategory))
        {
            $cats[$cat_title][]  $subcat_title;
        }
    }
    

    This will give you an array of arrays. The first array contains the category titles as keys and they will contain an array of all the sub category titles.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?