Welcome Guest, Not a member yet? Register   Sign In
can i pass data from view to controller?
#9

[eluser]gRoberts[/eluser]
Hi there,

As mentioned before showing any code, you would need to use the "in" statement when passing the PostID's.

You will need to change, or at least create a new method within your model to something like the following:

Code:
public function getComments($PostIDs)
{
  if(!is_array($PostIDs))
   $PostIDs = array($PostIDs);
  $this->db->select('comments.comment, comments.postId, comments.id, posts.id, comments.date, posts.userId');
  $this->db->join('posts', 'posts.id = comments.postId', 'left');
  $this->db->where_in('posts.id', $PostIDs);
  $q = $this->db->get('comments');
  $Ret = array();
  foreach($q->result() as $Comment)
   $Ret[] = $Comment;
  return $Ret;
}

Within your controller, as I had posted in my initial reply, you will see how the $Post->Comments is populated. I was getting all of the posts, then all of the comments related to those posts and then looping through the posts and assigning each posts comments to the post.

This is far better than looping through each of the posts and then querying the database for the list of comments.


Messages In This Thread
can i pass data from view to controller? - by El Forum - 04-25-2012, 11:09 AM
can i pass data from view to controller? - by El Forum - 04-25-2012, 11:22 AM
can i pass data from view to controller? - by El Forum - 04-25-2012, 07:53 PM
can i pass data from view to controller? - by El Forum - 04-25-2012, 07:55 PM
can i pass data from view to controller? - by El Forum - 04-25-2012, 07:59 PM
can i pass data from view to controller? - by El Forum - 04-25-2012, 08:02 PM
can i pass data from view to controller? - by El Forum - 04-26-2012, 03:16 AM
can i pass data from view to controller? - by El Forum - 04-26-2012, 06:58 AM
can i pass data from view to controller? - by El Forum - 04-26-2012, 07:08 AM
can i pass data from view to controller? - by El Forum - 04-26-2012, 10:32 AM
can i pass data from view to controller? - by El Forum - 04-30-2012, 06:30 AM
can i pass data from view to controller? - by El Forum - 04-30-2012, 11:23 AM
can i pass data from view to controller? - by El Forum - 04-30-2012, 11:29 AM
can i pass data from view to controller? - by El Forum - 04-30-2012, 11:32 AM
can i pass data from view to controller? - by El Forum - 04-30-2012, 11:36 AM
can i pass data from view to controller? - by El Forum - 04-30-2012, 12:31 PM
can i pass data from view to controller? - by El Forum - 04-30-2012, 04:11 PM
can i pass data from view to controller? - by El Forum - 05-01-2012, 07:01 AM
can i pass data from view to controller? - by El Forum - 05-01-2012, 09:45 AM
can i pass data from view to controller? - by El Forum - 05-01-2012, 11:33 AM
can i pass data from view to controller? - by El Forum - 05-01-2012, 12:26 PM
can i pass data from view to controller? - by El Forum - 05-01-2012, 12:31 PM
can i pass data from view to controller? - by El Forum - 05-01-2012, 12:38 PM
can i pass data from view to controller? - by El Forum - 05-01-2012, 12:52 PM
can i pass data from view to controller? - by El Forum - 05-01-2012, 01:42 PM
can i pass data from view to controller? - by El Forum - 05-01-2012, 02:39 PM
can i pass data from view to controller? - by El Forum - 05-01-2012, 04:20 PM
can i pass data from view to controller? - by El Forum - 05-02-2012, 12:40 AM
can i pass data from view to controller? - by El Forum - 05-02-2012, 09:55 AM
can i pass data from view to controller? - by El Forum - 05-02-2012, 01:13 PM
can i pass data from view to controller? - by El Forum - 05-02-2012, 01:32 PM
can i pass data from view to controller? - by El Forum - 05-02-2012, 01:35 PM
can i pass data from view to controller? - by El Forum - 05-02-2012, 01:39 PM
can i pass data from view to controller? - by El Forum - 05-02-2012, 02:23 PM
can i pass data from view to controller? - by El Forum - 05-02-2012, 08:47 PM
can i pass data from view to controller? - by El Forum - 05-03-2012, 07:36 AM
can i pass data from view to controller? - by El Forum - 05-03-2012, 11:06 AM
can i pass data from view to controller? - by El Forum - 05-03-2012, 11:31 AM
can i pass data from view to controller? - by El Forum - 05-03-2012, 12:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB