ueon Posted August 21, 2011 Share Posted August 21, 2011 The individual while loops work, but when I embed it within a while the parent loop runs, but the inner loop doesn't execute at all while ($set3 = mysql_fetch_array($query2)){ while ($set2 = mysql_fetch_array($query)){ echo $set2['EmailAddress']; } } Quote Link to comment https://forums.phpfreaks.com/topic/245357-while-loop-in-while-loop/ Share on other sites More sharing options...
Alex Posted August 21, 2011 Share Posted August 21, 2011 There's nothing inherently flawed with nested while loops, so the problem is with your code, but you're not giving us enough context to see what the issue is. Try posting several lines above that. Quote Link to comment https://forums.phpfreaks.com/topic/245357-while-loop-in-while-loop/#findComment-1260184 Share on other sites More sharing options...
teynon Posted August 21, 2011 Share Posted August 21, 2011 I can identify an issue with your logic already, as: while ($set2 = mysql_fetch_array($query)) mysql_fetch_array - Returns an array that corresponds to the fetched row and moves the internal data pointer ahead. "moves the internal data pointer ahead" This means once the pointer moves to the end, it will not be looped again unless you reset the pointer like so: mysql_data_seek($query); I would like to see the rest of your code, though, as it looks like you may have more issues. Quote Link to comment https://forums.phpfreaks.com/topic/245357-while-loop-in-while-loop/#findComment-1260185 Share on other sites More sharing options...
Alex Posted August 21, 2011 Share Posted August 21, 2011 I can identify an issue with your logic already, as: while ($set2 = mysql_fetch_array($query)) mysql_fetch_array - Returns an array that corresponds to the fetched row and moves the internal data pointer ahead. "moves the internal data pointer ahead" This means once the pointer moves to the end, it will not be looped again unless you reset the pointer like so: mysql_data_seek($query); I would like to see the rest of your code, though, as it looks like you may have more issues. The OP doesn't want to loop through the same results multiple times, and the loops use different MySQL results, so that shouldn't be an issue. It will be looped again if there are multiple results. Quote Link to comment https://forums.phpfreaks.com/topic/245357-while-loop-in-while-loop/#findComment-1260190 Share on other sites More sharing options...
teynon Posted August 21, 2011 Share Posted August 21, 2011 Essentially his logic would look like this: Loop1 Output Loop2 Output Loop2 Output Loop2 Output Loop2 Output Loop1 Output Loop1 Output Loop1 Output Loop1 Output Loop2 would execute once and then never do anything again. But as we have both said, we need the rest of the code to understand what you're doing. Quote Link to comment https://forums.phpfreaks.com/topic/245357-while-loop-in-while-loop/#findComment-1260192 Share on other sites More sharing options...
Alex Posted August 21, 2011 Share Posted August 21, 2011 Oh sorry, I misinterpreted what you meant. Yeah, we don't even know what your intending output is, so we can't help you fix it. Quote Link to comment https://forums.phpfreaks.com/topic/245357-while-loop-in-while-loop/#findComment-1260199 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.