我想得到结果:
parent1 : child1 child1 child1
parent2 : child2 child2 child2
parent3 : child3 child3 child3
parent4 : child4 child4 child4
表名是“类别”,parent_id=0
是父类,我想得到每个父亲的孩子。我使用 yii 框架下面是我的代码:
class CtcategoryController extends GtController
{
public function actionIndex()
{
$criteria = new CDbCriteria;
$criteria -> select = 'id,name';
$criteria -> limit = 15;
$criteria -> condition = 'parent_id = 0';
$categorys = CtCategory::model()->findAll($criteria);
foreach($categorys as $category_child){
$criteria -> condition = 'parent_id = '.$category_child->id;
$category_child = CtCategory::model()->findAll($criteria);
}
//print_r($category_child);==>Aarray() is null;
$this->render('index', array(
'categorys' => $categorys,
array('category_child' => $category_child)
));
}