return result of recursively executed query using codeigniter -
i new codegniter. have used following code execute function recursively.
in first call pass reply_id in function have used query select id having
parent_id = reply_id in foreach same process selected ids.
now want return combine array recursion.because each id query executed , new result each time.
how can that??
$resultq3 = $this->showreply($reply_id); //first call function <?php public function showreply( $reply_id ) { $q1 =$this->db->select('*') ->from('forum_reply fr') ->where('fr.parent_id',$reply_id) ->order_by('fr.id ')->get();; foreach( $q1->result_array() $row4 ) { $id = $row4['id']; $parent_id = $row4['parent_id']; if( $parent_id !=0 ) { $this->showreply( $id ); } } return $result; //here want return result } ?>
edited code:
$resultq3 = $this->showreply($reply_id); //first call function <?php public function showreply( $reply_id ) { $q1 =$this->db->select('*') ->from('forum_reply fr') ->where('fr.parent_id',$reply_id) ->order_by('fr.id ')->get();; foreach( $q1->result_array() $row4 ) { $arr1 = $q1->result_array(); $arr = array_merge($arr, $arr1); $id = $row4['id']; $parent_id = $row4['parent_id']; if(!empty($arr1)) { $this->showreply( $id ); } } return $arr; } ?>
just replace code. call functionally single param($replay_id
) first time..
<?php public function showreply($reply_id, $id = array()) { $q1 =$this->db->select('*') ->from('forum_reply fr') ->where('fr.parent_id',$reply_id) ->order_by('fr.id ')->get();; foreach( $q1->result_array() $row4 ) { array_push($id, $row4); //push ever data want $parent_id = $row4['parent_id']; if( $parent_id !=0 ) { $this->showreply($row4['id'], $id); } } return $id; //here want return result } ?>
Comments
Post a Comment