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.
memberID= what ever is the primary key for the member table $sql="SELECT * FROM members ORDER BY memberID DESC LIMIT 10";
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.
<?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.
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: