Results 1 to 3 of 3

Thread: php loop problem

  1. #1
    Join Date
    Jun 2007
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default php loop problem

    Is it possible to execute a return function a certain times based on a variable containing a number. I don't want echo or anything so. This is my code that doesn't work:

    PHP Code:
    function board($number) {for ($num=1$num<=10$num++ ) 

    return 
    "xx"
    } } 
    In short. The above should return, $number of times...but doesn't per definition...any solutions?

    The reason I use return and not echo is becuase the above code is part of a variable containing html code to be written to a file...

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    what you posted by itself is fine, but you say its part of something else...
    please post more of your code so we can determine where the error is occuring.

  3. #3
    Join Date
    Jun 2007
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Oki here is a stripped version of the phpscript:

    PHP Code:
    <?php
    $file 
    fopen("formsaved.html""w") or exit("Unable to open file!"); 

    function 
    board($number) {for ($num=1$num<=10$num++ ) 

    return 
    "test"
    } }





    $stringData 

    '
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <form id="form" name="form" method="post" action="writeform.php">
      <table width="610" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td valign="top">'
    .board(5).'</td>
        
        </tr>
        </table>
     
    </form>
    </body>
    </html>

    '


    ;
    fwrite($file$stringData);  
    fclose($file);

    header("Location: formsaved.html");


    ?>

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
  •