Please Help Me Selecting MySQL Top Row

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Please Help Me Selecting MySQL Top Row

    My database table name is users and colums are id,name,mobile,facebook....
    Now i want to display first 10 members data....
    How can i do that?
    Please give me tested and working code....
    If possible give me a full php file....
    I badly need it......

    #2
    Originally posted by Rockto View Post
    My database table name is users and colums are id,name,mobile,facebook....
    Now i want to display first 10 members data....
    How can i do that?
    Please give me tested and working code....
    If possible give me a full php file....
    I badly need it......
    try this for example
    sorry if i wrong
    Attached Files

    Comment


      #3
      Originally posted by gammz View Post
      try this for example
      sorry if i wrong
      Thanks for replay and file...i gonna test it...

      Comment


        #4
        Here you go.


        Code:
        select * from users limit 10
        The
        Code:
        *
        means select all columns in the table, and the
        Code:
        limit 10
        means only return the first 10 rows/records in the result

        Depending on what MySQL version you are using you will typically use the code as follows.

        OLD SQL:

        PHP Code:
        $sql 'select * from users limit 10';
        $query mysql_query($sql);

        while (
        $row $query)
        {

        $row['username'//Just insert your column name you want


        PDO:

        PHP Code:
        $sql 'select * from users limit 10';
        $query $db->query($sql);

        while (
        $row $query->fetch(PDO::FETCH_ASSOC))
        {
        $row['username']; //Just insert your column name you want 

        Comment


          #5
          Say Thanks If you Like

          Hello Brother If you have the field name id in your table then use this code

          SELECT * FROM `table_name` ORDER BY `id` DESC LIMIT 0,10 <- This is for last 10 fields


          SELECT * FROM `table_name` ORDER BY `id` ASC LIMIT 0,10 <- This is for First 10 fields

          Comment

          Working...
          X