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 3 of 3
  1. #1
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,501
    Thanks
    72
    Thanked 105 Times in 104 Posts

    How do I increase +1 in while loop?

    I am using a WHILE loop to extract data from the database. I want it to show, 1,2,3,4,5 and keep counting up every record it pulls. What do I add for the +1?

    PHP Code:
    echo '<select name="fire">';
              while (
    $runecheck mysql_fetch_array($runecheck2))
              {
                
    $inc $inc +1;
                echo 
    "<option value="$inc">$inc Runes</option>";
              }
              echo 
    '</select>'

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,307
    Thanks
    4
    Thanked 205 Times in 202 Posts
    What you have should work but it might be clearer to do it like this:

    PHP Code:
    $inc 0;
    echo 
    '<select name="fire">';
              while (
    $runecheck mysql_fetch_array($runecheck2))
              {
                
    $inc++;
                echo 
    '<option value="' $inc '">' $inc ' Runes</option>';
              }
              echo 
    '</select>'
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    myfayt (11-08-2010)

  • #3
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,501
    Thanks
    72
    Thanked 105 Times in 104 Posts
    Thanks! I couldn't remember the $inc++; part.


  •  

    Posting Permissions

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