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?

有帮助吗?

解决方案

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);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top