How do I make a loop for my simple PHP coding?

Discussion in 'PHP' started by project168, Mar 26, 2011.

  1. #1
    Is there a program which provides this compiling method?
     
    project168, Mar 26, 2011 IP
  2. TimK

    TimK Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That's correct. It will loop until acted on by an outside influence.
     
    TimK, Mar 26, 2011 IP
  3. benims

    benims Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yes. this code isnt it corrent ?
     
    benims, Mar 27, 2011 IP
  4. project168

    project168 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I added this part in, so it can perform infinite loop. Is this right? But I get errors executing it since variable 'i' is not declared.

     
    project168, Mar 27, 2011 IP
  5. srisen2

    srisen2 Peon

    Messages:
    359
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    try setting i to 1 outside of the while loop
     
    srisen2, Apr 4, 2011 IP
  6. lukefowell89

    lukefowell89 Peon

    Messages:
    182
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Agree as above, you cant expect to be able to + 1 to a variable which hasn't been instantiated. Set it to 0 or 1 before, outside the loop
     
    lukefowell89, Apr 4, 2011 IP
  7. shrikrishnatechnologies

    shrikrishnatechnologies Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Try this simple code for looping

    $brush_price = 5; 
    
    echo "<table border=\"1\" align=\"center\">";
    echo "<tr><th>Quantity</th>";
    echo "<th>Price</th></tr>";
    for ( $counter = 10; $counter <= 100; $counter += 10) {
    	echo "<tr><td>";
    	echo $counter;
    	echo "</td><td>";
    	echo $brush_price * $counter;
    	echo "</td></tr>";
    }
    echo "</table>";
    
    Code (markup):