Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: The while loop

  1. #1
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts

    The while loop

    I cant do this while loop in a array, it doesn't work, maybe it is the while loop, but I am pretty sure that it is the while loop not working how I am doing this, probably syntax error.
    PHP Code:
    $authorize '1';
    $authorized count(file("authorized.dat"));
    $authorized_IP file("authorized.dat");
    while(
    $authorize >= $authorized){
          echo (
    "<OPTION value='$authorize'>");
          echo 
    $authorized_IP[$authorize];
          
    $authorize++;

    I think it is this line:
    PHP Code:
    echo $authorized_IP[$authorize]; 
    How can I fix this?

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What kind of errors do you get when you run this script?

  • #3
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay, got it! You cant use the while look on this, you must use the for loop. At least with what I got..

    PHP Code:
    <?php
    $x 
    '1';
    $authorized file("authorized.dat");
    $authorized count($authorized);
    $authorized_IP file("authorized.dat");
    for (
    $x 1$x $authorized$x++) {
          echo (
    "<OPTION value='$x'>");
          echo 
    $authorized_IP[$x];
          echo (
    "<br>");
    }
    ?>
    Hope that helps!

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    your code should work ... but

    >= should be <=

    else your loop will never start in the first place , also $authorize should be initialised as 0 since thats where the array index starts (unless the first line is simply descriptive/metadata);
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $authorize '1'
    Just wondering why there would be quotes here... you're wanting to increment a string? Get rid of the quotes and also do what firepages said..

    Let us know how that works out for you.

    Sadiq.

  • #6
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just had to do what firepages said, then it worked great, and that will help me alot in the future probably

    I didn't know you could do that with arrays


  •  

    Posting Permissions

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