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

Link to comment
Share on other sites

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();

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.