Results 1 to 2 of 2

Thread: while() loop question...

  1. #1
    Join Date
    Apr 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default while() loop question...

    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?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •