Welcome to WebmasterWorld Guest from 174.129.66.66

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)

Preferred Member

10+ Year Member

joined:Aug 20, 2004
posts: 615
votes: 0


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)

Senior Member

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

joined:July 3, 2006
posts: 3123
votes: 0


$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)

Preferred Member

10+ Year Member

joined:Aug 20, 2004
posts: 615
votes: 0


Penders -

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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members