Welcome Guest, Not a member yet? Register   Sign In
handling query results with codeigniter
#2

[eluser]BrianDHall[/eluser]
[quote author="joeizang" date="1254943868"]
Code:
function gettitle3()
{
$this->db->select('articletitle');
$this->db->from('articles');
$this->db->where('articlecategory',2);
$query = $this->db->get();
if($query->num_rows() > 0)
{
$Q = $query->result_array();
foreach($Q as $value){
return $value;
  }
}
}
[/quote]

Your problem is your foreach. What is happening is the foreach gets one of the values in the $Q array and puts it into $value, then you call return - that breaks for the foreach loop and ends the function.

Doing it this way will ensure you never get more than the first result. Replace "return $value;" with "echo $value;" to see if it works.


Messages In This Thread
handling query results with codeigniter - by El Forum - 10-07-2009, 08:31 AM
handling query results with codeigniter - by El Forum - 10-07-2009, 08:36 AM
handling query results with codeigniter - by El Forum - 10-07-2009, 08:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB