How can I keep the foreach statement from outputting multiple’s of the same row? I need it to just output all the rows that meet the Sql requirement one time. Any ideas?
$query = $this->db->query("SELECT * FROM churchMembers WHERE cMuserId = '{$userid}'");
$row = $query->row();
$membersChurchId = $row->cMchurchId;
$query = $this->db->query("SELECT wp.entryData, u.firstname, u.userid
FROM wallPosts wp, users u
WHERE wp.wpChurchId = '{$membersChurchId}'");
foreach ($query->result() as $row) {
echo $row->entryData.nl2br("\n");
}
Update
After discussing the problem, it was the problem with the query.
The correct query in your case will be
I think you are approaching this the wrong way.If you need to output all the rows, that meet your requirements, at one time, then you have to create a function, which reads the rows and build the output. But still you will be using the foreach
Now include this function in a helper or whatever you like as use it in your code like
However the method I wrote above is only good, when you are using the function in more than one occasion