Jump to content

[SOLVED] Using A While Loop In A For Loop - Can This Be Done?


Recommended Posts

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> ";
}
}

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.

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> ";
}
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.