Welcome Guest, Not a member yet? Register   Sign In
Loop inside a loop in controller.. help needed....:(
#1

[eluser]Roy MJ[/eluser]
Hi guys,

Can anyone help me solve this problem. Im having one table members which contain details of registered people. And another table friends linking the ids to make them friends. the table structure is as follows :

Code:
Table friends

id     member_id     friend     status
1     12             17     0
9     13             17     0
3     12             29     0

Bu i need to display the friends details as in any social networking site. Like name, photo etc. But all that contents are in another table called members. Hoe can i connect the two tables together in the controller part..

The existing controller for displayin frnds is as follows :


Code:
function index($pgoffset='')
    {
        //$this->data['service'] = $this->Services_model->select_services();
        $this->data['pagetitle'] ='Friends List';
        if(($this->session->userdata('user_id'))!=NULL)
        {
            $row    =      $this->Profile_model->get_selected($this->session->userdata('user_id'));
            $this->data['username'] = $row->username;
            $id =  $row->id;
        }
        $config['per_page'] = 20;
        $config['total_rows'] = $this->Friends_model->get_total($id);
        $config['base_url'] = site_url().'/friends/index/';
        $config['uri_segment'] = 3;
        $this->data['friends'] = $this->Friends_model->select_friends($config['per_page'], $pgoffset,$id);
        $this->data['pgoffset'] = $pgoffset;
        $this->pagination->initialize($config);
        $this->load->view('profile/friends', $this->data);
    }
The model :

Code:
function get_total($id)
    {
        $count=0;
        $this->db->select('COUNT(id) AS total');
        $this->db->distinct();
        $this->db->from('friends');
        /*$this->db->where($where);*/
        $this->db->where('member_id', $id);
        $result_total = $this->db->get();
        if($result_total->num_rows()>0){
            $row    = $result_total->row();
            $count    =    $row->total;
        }
        return $count;
    }
   function select_friends($limit, $pgoffset,$id)
   {
           $this->db->select('friend');
           $this->db->limit($limit, $pgoffset);
        $this->db->distinct();
        $this->db->from('friends');
        $this->db->where('member_id', $id);
        $result_news = $this->db->get();
          return $result_news->result();
        //$result_news = $this->db->query('select * from news');
   }

View :
Code:
<?php    foreach($friends as $row){?>
<div id="friends">
<a class="newshead">friend?&gt;">&lt;?php echo $row->friend?&gt;</a><br />
</div>                    
&lt;?php } ?&gt;
<div>&lt;?php echo $this->pagination->create_links(); ?&gt;</div>


Messages In This Thread
Loop inside a loop in controller.. help needed....:( - by El Forum - 04-03-2011, 11:21 PM
Loop inside a loop in controller.. help needed....:( - by El Forum - 04-03-2011, 11:28 PM
Loop inside a loop in controller.. help needed....:( - by El Forum - 04-04-2011, 12:19 AM
Loop inside a loop in controller.. help needed....:( - by El Forum - 04-04-2011, 01:07 AM
Loop inside a loop in controller.. help needed....:( - by El Forum - 04-04-2011, 11:59 PM
Loop inside a loop in controller.. help needed....:( - by El Forum - 04-05-2011, 12:12 AM
Loop inside a loop in controller.. help needed....:( - by El Forum - 04-05-2011, 12:22 AM
Loop inside a loop in controller.. help needed....:( - by El Forum - 04-05-2011, 12:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB