cakephp - Creating drop down tree in php -


i have table structure following

|id| parent_id |name| 

parent_id referring same table recursively tried create drop-down tree unsuccessful. please tell how create in core php or cake php.

this work did far..but give error 'fatal error: allowed memory size of 134217728 bytes exhausted (tried 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 $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.='-';  } 

i'm not sure mean "want parent ids , child ids separated." understand elements in select nothing more display value , data value, , data value gets sent server along field name.

so select can't distinguish between multiple kinds of data values. each option can't have multiple ids, example. format display value include ids (such have "1 - games - 0" , such), , decide data value should value option in select.

one thing can group option elements, using optgroup tag. this:

<select name="myoptions">   <optgroup label="category 1">     <option value="1">first choice</option>     <option value="2">second choice</option>     <option value="3">third choice</option>   </optgroup>   <optgroup label="category 2">     <option value="4">fourth choice</option>     <option value="5">fifth choice</option>   </optgroup>   <optgroup label="category 3">     <option value="6">sixth choice</option>     <option value="7">seventh choice</option>   </optgroup> </select> 

in validation, browser shouldn't allow user select group, have select actual option. shouldn't have worry that. present additional flexibility in displaying values more hierarchically. understand, however, 1 level of option nesting allowed in case. (so optgroup can't contain optgroup.)


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -