php - how to read a specific field from an array returned by the model in the controller itself -


i have function in controller "thistopic" has following:

$viewdata = array(); $viewdata['reply']   = $this->disc->get_all_replies($topic_id); $viewdata['firstreply']= $this->disc->get_firstreply();  

in model:

public function get_all_replies($topic_id){      return $results =  $this->db->select('*')                      ->from('disc_replies')                      ->join('users', 'users.id = disc_replies.users_id')                      ->where('topic_id',$topic_id)                      ->get()->result(); }  public function get_firstreply($reply_id){      return $results =  $this->db->select('*')                      ->from('disc_firstreply')                      ->join('users', 'users.id = disc_firstreply.users_id')                      ->where('reply_id',$reply_id)                      ->get()->result(); } 

the disc_replies table has following columns:

1. reply_id 2. topic_id 3. users_id 4. replied_on 

from $viewdata['reply'] want read reply_id field of first row , sent parameter get_firstreply() function.

this tried far:

$viewdata['firstreply']= $this->disc->get_firstreply($viewdata['reply'][0]['reply_id']);  $viewdata['firstreply']= $this->disc->get_firstreply($viewdata['reply']['reply_id']); 

but nothing works, solve problem appreciated. in advance

in order use $viewdata['reply'][0] (0 pointed array) in codeigniter, have format array objective array.

this

->get()->result(); 

should change as

->get()->result_array(); 

you can check format of array using print_r($viewdata['reply'])


make sure $viewdata['reply'] not empty


Comments