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
    New Coder
    Join Date
    Jun 2006
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SQL query not working properly

    I've just recently decided to dabble into MySQL with PHP. So far so good, except for one thing. My script executes fine, no errors, but for some reason it will not grab the first row in my table.

    What I mean is this:

    Row 1
    Row 2
    Row 3

    In my PHP script, it grabs the information from the database and just displays it. It will display "Row 2 data <br> Row 3 data", but for some reason, it will not display the data in Row 1.

    Here's my script (pretty simple):

    PHP Code:
    <?
    $user
    ="xxxxx";
    $password="xxxxx";
    $database="xxxxx";
    mysql_connect(localhost,$user,$password);
    mysql_select_db($database) or die("Unable to select database");

    $result mysql_query("SELECT * FROM users") or die(mysql_error());  

    $row mysql_fetch_array($result);

    while(
    $row mysql_fetch_array($result)){
        echo 
    $row['USERID']. " - "$row['NAME'];
        echo 
    "<br>";
    }

    mysql_close();
    ?>
    Here's my script running right now, for a better example: Clicky

    Any ideas?

    Thanks in advance for the help.

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Get rid of the line where you are assigning $row before the while block. You don't need to do that, it will do it before the first iteration of the block.

    Right now with that there, you are basically skipping over the first row.
    OracleGuy

  • #3
    New Coder
    Join Date
    Jun 2006
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ah, worked perfectly. Thank you very 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
    •