Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Looking at the next row in a while loop



12:16 pm on Dec 8, 2012 (gmt 0)

10+ Year Member

Hello All -

I'm pulling various values from a table.

From there I'm processing the result through a while loop.

what I'm trying to do is to look AHEAD at a particular value in the NEXT row set but I'm having a very difficult time trying to get this done.

Shown below is pseudo code to better illustrate what I'm trying to accomplish.

$ignore = NULL;

while($d = mysql_fetch_assoc($r))
if($d['fld_nav_index'] == $ignore) continue;

$test1 = $d['fld_nav_index'];
$test2 = next($d['fld_nav_index']); // value in the NEXT row

if($test2 == '02') {
echo $test1;
$ignore = $test2;

Is there a simple solution to this problem?

All help greatly appreciated.


2:02 pm on Dec 8, 2012 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

$test2 = next($d['fld_nav_index']); // value in the NEXT row

The next() function moves the internal array pointer of the passed array and returns the next element. $d['fld_nav_index'] is not an array. This should trigger a PHP E_WARNING?

Rather than trying to look ahead to the next row, I think it might be easier to remember the previous row and look back - so you always have two entire rows in memory. Assuming you need to examine every row and not every other row.


1:14 am on Dec 9, 2012 (gmt 0)

10+ Year Member

Penders -

Thanks very much for your suggestion and insight - have found a solution (that should have been obvious to me before) for this issue.

Featured Threads

Hot Threads This Week

Hot Threads This Month