PDA

View Full Version : while() loop question...



SessTehKing
05-11-2007, 10:41 PM
With the while() loop, is there anyway for the code inside to not be repeated, but instead replace that last while() output? Or is this not possible due to it being server-side? I'm trying to repeat a javascript function, and it's not working out when it is echoed 10 times back-to-back...any solution in general?

djr33
05-11-2007, 10:47 PM
I think you are thikning about this backwards.

PHP is seperate from Javascript.

PHP runs as a program, outputting text.

That text, then, is served to the user. The user never sees the PHP at all, just what it outputs.

As such, any Javascript exists AFTER and only after it is sent from PHP to the user. (The text representing this is in the PHP script, but not active.)

You can't have PHP do javascript, only output javascript functions that will later do stuff.

As for a while loop that doesn't repeat... well... that's not the point.

If you had:
while ($x<10) {
$x++;
echo $x;
}

You could instead use:
while ($x<10) {
$x++;
}
echo $x;

in which case, the echo is outside the loop, so it only outputs once.

Or, to really not repeat:
$x++;
echo $x;

But I assume that isn't what you're after.

Please give more information if you need more help. Good luck.