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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    php auto increment doesn't work when showing rows

    This is my code:


    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","root","");
    if (!
    $con)
      {
      die(
    mysql_error());
      }
    $i=1;
    mysql_select_db("list"$con);

    $result mysql_query("SELECT * FROM users
    WHERE id='$i'"
    );

    while(
    $row mysql_fetch_array($result))
      {
      echo 
    $row['id'] . " " $row['name'];
      echo 
    "<br />";
      
      echo 
    $row['id'] . " " $row['name'];

      echo 
    "<br />";
      
    $i++;

      }
    ?>
    For some reason it just doesn't increases so I get:

    1 John
    1 John
    Last edited by Krentenbol; 11-29-2011 at 02:31 PM.

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    You are only pulling one row from your users table, the row with the ID of 1 so that is why you'll only see that one printed out in your while loop.
    OracleGuy


  •  

    Posting Permissions

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