Jump to content

codeigniter previous_row and next_row problem


c_pattle

Recommended Posts

I have the following code

 

<? $i=1; ?>
        <? foreach ($query4->result_array() as $row4): ?>
        
        <? $next = $query4->next_row('array'); ?>
        <? $prev = $query4->previous_row('array'); ?>

<? $i++; ?>
<? endforeach; ?>

 

However when I run this the next_row() and previous_row() functions only work on the first loop.  So on the first run through they get the next row or previous row but then they seem to stop. 

 

Then whenever I do a var_dump on the $next and $prev variables they still contain the data for the second row. 

 

Does anyone know what I'm doing wrong? 

 

Thanks

I don't think you need to use a foreach loop if you are using next_row and previous_row. Take a look at the docs again. Start with a single row by using row_array.

 

$row = $query->row_array();

$next = $query->next_row();

$prev = $query->previous_row();

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.