I've two tables `sermons(sermon_id,preacher_id,sermon_name etc)` and `preachers(preacher_id,firstname,lastname etc)`. Now i display this like 1st preacher name then all the sermons of that preacher and so on , this is working properly. But want to display preachers who have sermons...

following code is used but i got only the 1st preacher..

```
function viewAllpreachers($offset=0, $limit=null) {
        $preacher_ids = array();
        $this->db->distinct('preacher_id');
        $this->db->select('preacher_id');
        $this->db->from('sermons');

        $query = $this->db->get();

        if ($query->num_rows() > 0) {

            foreach ($query->result() as $key => $res1) {

                $preacher = array();
                $this->db->select('*');
                $this->db->from('preacher');
                $this->db->where('preacher_id', $res1->preacher_id);
                $this->db->order_by('first_name');
                $query = $this->db->get('', $limit, $offset);
                if ($query->num_rows() > 0) {

                    foreach ($query->result() as $row) {
                        $preacher[$row->preacher_id]['preacher_id'] = $row->preacher_id;
                        $preacher[$row->preacher_id]['preacher_name'] = $row->first_name . ' ' . $row->last_name;
                        $preacher[$row->preacher_id]['preacher_image'] = $row->preacher_image;
                        $preacher[$row->preacher_id]['preacher_bio_brief'] = $row->preacher_bio_brief;

                        $this->db->select('*');
                        $this->db->from('sermons');
                        $this->db->where('preacher_id', $row->preacher_id);
                        $this->db->order_by('sort_order ');
                        $sermon_array = array();

                        $query = $this->db->get();
                        if ($query->num_rows() > 0) {
                            foreach ($query->result() as $row1) {
                                $sermon_array[$row1->sermon_id] ['sermon_image'] = $row1->sermon_image;
                                $sermon_array[$row1->sermon_id] ['sermon_title'] = $row1->sermon_title;
                                $sermon_array[$row1->sermon_id] ['audio_file'] = $row1->audio_file;
                                $sermon_array[$row1->sermon_id] ['sermon_description'] = $row1->sermon_description;
                            }
                        }
                        $preacher[$row->preacher_id]['sermon'] = $sermon_array;
                    }
                    return $preacher;
                }
            }  }
        return false;
    }

```