c_pattle Posted December 19, 2011 Share Posted December 19, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253475-codeigniter-previous_row-and-next_row-problem/ Share on other sites More sharing options...
sKunKbad Posted December 20, 2011 Share Posted December 20, 2011 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(); Quote Link to comment https://forums.phpfreaks.com/topic/253475-codeigniter-previous_row-and-next_row-problem/#findComment-1299588 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.