0
我使用kohana框架,我試圖編寫遞歸函數來創建類別樹。遞歸函數創建數組
我的分類表
id int(11) NO PRI NULL auto_increment
name varchar(50) NO NULL
parent_id int(11) NO NULL
projects_count int(11) NO NULL
我的例子不是工作
public static function category_list($parent_id = 0)
{
$result = Database::instance()->query('
SELECT name, projects_count
FROM project_categories
WHERE parent_id = ?',
array($parent_id)
);
$project_categories = array();
foreach($result as $row)
{
$project_categories[] = $row;
Project_Categories_Model::factory()->category_list($parent_id + 1);
}
return $project_categories;
}