slarson20 Posted September 12, 2011 Share Posted September 12, 2011 why does while($random_user_TOTAL_COUNT <= 15 && $random_user_INFO = $random_user_USERS->fetch_object()){ work, but while($random_user_INFO = $random_user_USERS->fetch_object() && $random_user_TOTAL_COUNT <= 15){ doesn't. why??? Link to comment https://forums.phpfreaks.com/topic/246937-while-loop-confusion/ Share on other sites More sharing options...
Pandemikk Posted September 12, 2011 Share Posted September 12, 2011 I'd assume when executing the expression the loops tries to assign the && logic operator and $random_user_TOTAL_COUNT <= 15, which of course won't work. I'd suspect you'd run into similar troubles doing something like: <?php $foo = $bar AND $val = $i; ?> The solution is to use parenthesis to give operator precedence. <?php while(($random_user_INFO = $random_user_USERS->fetch_object()) && $random_user_TOTAL_COUNT <= 15) ?> http://www.php.net/manual/en/language.operators.precedence.php Link to comment https://forums.phpfreaks.com/topic/246937-while-loop-confusion/#findComment-1268195 Share on other sites More sharing options...
slarson20 Posted September 12, 2011 Author Share Posted September 12, 2011 Thanks so much man!!! life saver!!! Link to comment https://forums.phpfreaks.com/topic/246937-while-loop-confusion/#findComment-1268196 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.