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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.