I have a table structure like following
|id| parent_id |name|
parent_id
is referring to the same table recursively I tried to create a drop-down tree
but unsuccessful. Please tell it how to create in core php or Cake php.
this is the work i did so far..But it give error 'Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 67025477 bytes) in /viren/webroot/upms/app/controllers/tests_controller.php on line 390';
function admin_takecat(){
$this->layout=false;
$this->render(false);
Configure::write('debug',2);
$firstlevel=$this->cats->find('list',array('fields'=>array('Category.id','Category.cat_name'),'conditions'=>array('Category.parent_id'=>0,'department_id'=>9)));
$dropbox='<select>';
foreach($firstlevel as $id=>$val){
$dropbox.='<option value='.$id.'>'.$val.'</option>';
$count=$this->cats->find('count',array('conditions'=>array('Category.parent_id'=>0,'Category.department_id'=>9,'Category.parent_id'=>$id)));
if($count>0){
$dropbox=$this->_recursive($id,$dropbox,1);
}
}
$dropbox.='</select>';
echo $dropbox;
}
function _recursive($catid,$dropbox,$level){
$listcats=$this->cats->find('list',array('fields'=>array('Category.id','Category.cat_name'),'conditions'=>array('Category.parent_id'=>0,'Category.department_id'=>9,'Category.parent_id'=>$catid)));
$mark='';
for($i=1;$i<=1;$i++){
$mark.='-';
}