1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How can get first record from mySQL table?

Discussion in 'PHP' started by manojkumarmaithil, Jan 11, 2008.

  1. manojkumarmaithil

    manojkumarmaithil New Member

    Joined:
    Jun 18, 2007
    Messages:
    14
    Likes Received:
    1
    Trophy Points:
    0
    PHP:
    <?php 
    $db 
    mysql_connect("MySQLHOST""u70001653""8154f5");
    mysql_select_db("d60001233",$db);

    $query  "SELECT * FROM newuser ORDER BY entrydate";
    $sql_query =mysql_query($query,$db);
    $row=mysql_fetch_array($sql_query);
    ?>
    <?   
    <table>
    while($row = mysql_fetch_array($sql_query, MYSQL_ASSOC))
        {
     ?>
    <tr>
    <td><? echo $row["fullname</td>
    <td><? echo $row["address"];?></td>
    <td><? echo $row["admincheck"];?></td>
    <td><? echo $row["entrydate"];?></td>
    </tr>
    <? 
    }
    ?>
    </table>
    When we run this code then it produce list form second record. How can I get first record from Table?

    Any Idea!
     
    Last edited by a moderator: Jan 11, 2008
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Still you don't seem to get how to Post a Query as a thread and submit an article. You have submitted the above thread as an article and I have moved it to the forum.
     
  3. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Code:
    SELECT * FROM newuser ORDER BY entrydate LIMIT 1
    You may also use "SELECT * FROM newuser ORDER BY entrydate" but use if() instead of while()
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    The problem is you are executing the statement mysql_fetch_array twice before printing the result for the first time and so its getting from the record number 2
     

Share This Page