Loop inside a loop in controller.. help needed....:( |
[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 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='') Code: function get_total($id) View : Code: <?php foreach($friends as $row){?>
[eluser]Roy MJ[/eluser]
But the current code will only help me display all the friends ids. I need a way of getting all the details of the ids as friends from the members table. The structure for table members is as follows: Code: id firstname lastname screenname username password city state phone zip email The id in the members table and the field friend in friends table are the same.
[eluser]Roy MJ[/eluser]
Ive tried out join function and an error is logging in.. The model is as follows: Code: function get_total($id) The error is : Code: A Database Error Occurred I cant figure out why the error. 13 is actually the id thats getting passed.. Anyone..??
[eluser]Roy MJ[/eluser]
figured out.. but not sure this is the actual way.. Code: function get_total($id)
[eluser]Roy MJ[/eluser]
apparently the above code is nt workin properly. Its listing all contents from the members table.. anyone figure out a way around this??
[eluser]InsiteFX[/eluser]
See if this will work for you. Code: $this->db->join('members','friends.member_id', 'left'); Also try putting your where causes above your joins. InsiteFX
[eluser]Roy MJ[/eluser]
No its still listing all the contents from the table friends. The condition that Code: $this->db->where('friends.member_id =', $id); I have removed the condition $this->db->where('friends.status =', 1); also. But still no change...
[eluser]Roy MJ[/eluser]
I was thinking of a way where i can call anothr function in the model but im still a starter in codeigniter and i dun have the depth in this. In controller Code: $this->data['friends']=$this->Friends_model->select_friends($config['per_page'],$pgoffset,$id); And the model for this wud be to just get friends id from table friends. So that the details of friends can be got from another function in model. But that means ill have to pass the data as loop in the controller. Like Code: foreach($this->['friends']){ This is just an idea am i dunno whether its correct. Im a bit afraid cuz ill have to change the entire thing and the due date is up.. |
Welcome Guest, Not a member yet? Register Sign In |