Latest Registered Members script

Discussion in 'PHP' started by patco, Mar 4, 2010.

  1. #1
    Hello everybody. I made a site recently, but I have one very small problem now. I want to display the latest 10 online users. I tried twice to write the code on my own without any result, looking very hard online to find anything and I am confused. Please, be so kind to help me. Thank you very much in advance. :)
     
    patco, Mar 4, 2010 IP
  2. Narrator

    Narrator Active Member

    Messages:
    392
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    80
    #2
    memberID= what ever is the primary key for the member table

    $sql="SELECT * FROM members ORDER BY memberID DESC LIMIT 10";
     
    Narrator, Mar 4, 2010 IP
  3. patco

    patco Well-Known Member

    Messages:
    2,035
    Likes Received:
    47
    Best Answers:
    17
    Trophy Points:
    100
    #3
    member ID is just id. Is this the full code?
    <?php $sql="SELECT * FROM members ORDER BY memberID DESC LIMIT 10"; ?>
    because I think I must add mysql_fetch_array($sql) or something similar. Any other clues :). Thanks.
     
    patco, Mar 5, 2010 IP
  4. attila123

    attila123 Active Member

    Messages:
    113
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    
    <?php
    $sql="SELECT * FROM members ORDER BY memberID DESC LIMIT 10"; 
    $res=mysql_query($sql);
    
    while($row=mysql_fetch_array($res)) {
       print($row['username']."<br>");
    }
    
    ?>
    
    Code (markup):
    And, before this code, you have to connect to mysql server and select database.
     
    attila123, Mar 6, 2010 IP
  5. sunlcik

    sunlcik Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hope this may help you.

    
    <?php
    $connect	= mysql_connect("localhost","db_user","db_password") or die(mysql_error());
    mysql_select_db("db_name",$connect);
    //mysql_query("set names uft8");  you should set this line sometimes
    $query	= mysql_query("SELECT * FROM members ORDER BY memberID DESC LIMIT 10");
    
    while($row	= mysql_fetch_array($query)) 
    {
       print_r($row);
    }
    ?>
    
    PHP:
     
    sunlcik, Mar 6, 2010 IP
  6. patco

    patco Well-Known Member

    Messages:
    2,035
    Likes Received:
    47
    Best Answers:
    17
    Trophy Points:
    100
    #6
    Thank you very much. :)
     
    patco, Mar 6, 2010 IP