Results 1 to 3 of 3

Thread: [RESOLVED] for loop

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    147

    Resolved [RESOLVED] for loop

    i cant figure out whats wrong with this loop, it doesnt error out but it doesnt work

    for ($counter=1; $counter==20; $counter++) {
    $_5_price = "update_5_price";
    $_5_price.= $counter;
    $frame = "frame";
    $frame.= $counter;

    $style = "style";
    $style.= $counter;
    $style = $_REQUEST[$style];
    $style = preg_replace("/####/", " ", $style);

    echo $_5_price;
    echo "<br>";
    echo $frame;
    echo "<br>";
    echo $style;
    }

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: for loop

    You should use [php] tages to post code. Also, it is BAD to echo HTML.

    On to your error, your middle part of the for loop contains a condition but one which starts off as false (ie: is $coutner equal to 20). The for loop will execute the loop until the condition evaluates to false. If the condition is false to start it will never execute.

    What you need to do and what I think you meant to do is have the loop execute until the vlaue of $counter reaches 20. In this case you need the condition to evaluate to true every iteration prior to that:
    PHP Code:
    for ($counter=1$counter<=20$counter++) {
        
    $_5_price "update_5_price";
        
    $_5_price.= $counter;
        
    $frame "frame";
        
    $frame.= $counter;

        
    $style "style";
        
    $style.= $counter;
        
    $style $_REQUEST[$style];
        
    $style preg_replace("/####/"" "$style);

        echo 
    $_5_price;
        echo 
    "<br>";
        echo 
    $frame;
        echo 
    "<br>";
        echo 
    $style;

    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    147

    Re: for loop

    im sorry nearly first time posting in this forum.

    dude worked perfectly thanks much

Posting Permissions

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



Click Here to Expand Forum to Full Width