Reputation: 412
doing a simple Active Record select. It looks a little something like this:
$query = $CI->db->select( 'answer' )
->where( 'qID', $xid )
->get( 'qAnswer' );
$query becomes the expected CI_DB_mysql_result Object with result rows and a current row of 0. Expected.
while($row = $query->row() )
{
print_r( $row );
// some actual code
}
This is a commonly used pattern - but this time it triggers an infinite loop. When I output the row, it turns out that $query is dumping the first initial row infinitely many times. It is never iterating.
https://github.com/EllisLab/CodeIgniter/issues/2298 seems related but does not lead to a solution. Ideas?
Upvotes: 0
Views: 675
Reputation: 102
In Codeigniter function row() returns a single row. So you code become infinite. Try this construction:
foreach ($query->result() as $row){
print_r($row);
}
OR
while($row = $query->next_row() ){
print_r($row);
}
Upvotes: 1