Answer the question
In order to leave comments, you need to log in
How to perform a multi-level menu from a single table in Yii style?
Good afternoon, I used to use such 2 functions to display a hierarchical structure in the form of a multi-level menu. The function is recursive and calls itself. I tried to make it in the Yii style, but so far I'm a little lost in it.
The places are especially confusing - mysql_num rows() , mysql_query(), mysql_fetch_array()
Table Structure - CODE, CODE_PAR,
NAME I haven't changed the function yet. Please help Yii wizards \
[PHP]
public function getCat(){
//$sql = "SELECT CODE, `NAME`, CODE_PAR FROM t_product";
$condition = Product::findAll();
//$result = mysql_query($sql);
//if(!$result) return null;
if(!$condition) return null;
$arr_cat = array();
if(count(Product::model()->findAll()) != 0){
for($i = 0; $i < count(Product::model()->findAll()); $i++){
//$row = mysql_fetch_array($result, MYSQL_ASSOC);
$row = $condition;
//if(empty($arr_cat[$row['CODE_PAR']]))
if(empty($arr_cat[$row->CODE_PAR]))
//$arr_cat[$row['CODE_PAR']][] = array();
$arr_cat[$row->CODE_PAR][] = array();
// $arr_cat[$row['CODE_PAR']][] = $row;
//$arr_cat[$row->CODE_PAR][] = $condition;
$arr_cat[$row->CODE_PAR][] = $row;
}
}
return $arr_cat;
}
public function view_cat($arr, $code_par = 0){
if(empty($arr[$code_par])) return;
echo "
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question