homepage Welcome to WebmasterWorld Guest from 54.161.166.171
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Looking at the next row in a while loop
neophyte




msg:4526096
 12:16 pm on Dec 8, 2012 (gmt 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.

 

penders




msg:4526102
 2:02 pm on Dec 8, 2012 (gmt 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.

neophyte




msg:4526216
 1:14 am on Dec 9, 2012 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved