Jump to content

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


phpQuestioner

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.