phpQuestioner Posted November 28, 2007 Share Posted November 28, 2007 can you use a while loop inside a for loop; without contradicting or excluding your for loop? I would test it myself; except my server is having Server Error 500 issues right now. so I am not able to do a trial and error test at this time. something like this: for ($x = $skip2;$x<=$pagedisplay;$x++){ while ($myfield != $maxed_out) { echo " <a href=\"". $_SERVER['PHP_SELF'] ."?skip=$x\">". ($x+1) ."</a> "; } } Quote Link to comment Share on other sites More sharing options...
chantown Posted November 28, 2007 Share Posted November 28, 2007 What do you mean without contradicting? U will have to use two counting variables , one for each loop is that what you mean? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 28, 2007 Share Posted November 28, 2007 I don't see why not. Although, I'm sure you could figure out a way to get rid of the for loop altogether and do everything you need to in the while loop. I guess you would have to explain a situation...but yes, you can, it just may not be the best approach. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 28, 2007 Share Posted November 28, 2007 you can just not that loop as the 500 error is the inner loop nervier finishing you are comparing 2 variables that are never modified in the loop thus you will never reach a false (or true) statement Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 28, 2007 Author Share Posted November 28, 2007 cooldude832 - no, my server has been having this issue for two days now and it also happened about a month ago. about time to switch host, pretty mad at mine right now. thanks guys for your help - I finally decided to go with a if else condition in the for loop - that seemed to work out just fine; once I was able to test it in between server error issues. this is the way I did it: for ($x = $skip2;$x<=$pagedisplay;$x++){ if ($myfield != $maxed_out) { echo " <a href=\"". $_SERVER['PHP_SELF'] ."?skip=$x\">". ($x+1) ."</a> "; } else { echo " <a href=\"". $_SERVER['PHP_SELF'] ."?skip=". ($x-2) ."\">". ($x-1) ."</a> "; } } Quote Link to comment 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.