hoponhiggo Posted May 12, 2011 Share Posted May 12, 2011 Hi All I am using the below code to display users registered on my site: <div class="profilbox" id="apDiv11"><div></div> <div align="center">Registered Users</div> <div class="text_area"><?php //to display image from source - registerd users $dir = "profpics"; echo '<table>'; $result = mysql_query("SELECT * FROM users order by id"); while ($row = mysql_fetch_assoc($result)) { echo "<tr><td><img src=\"$dir/{$row['prof_pic']}\" width='40' height='40'>{$row['username']}</td></tr>"; } //close out table echo '</table>'; ?></div> </div> Could anybody tell me how i can limit this to 3 random results? I then plan adding a link to 'see all' Link to comment https://forums.phpfreaks.com/topic/236242-random-records/ Share on other sites More sharing options...
wildteen88 Posted May 12, 2011 Share Posted May 12, 2011 To get random results use ORDER BY rand() and use LIMIT 3 to limit the results to 3 rows. SELECT * FROM users order by rand() limit 3 Link to comment https://forums.phpfreaks.com/topic/236242-random-records/#findComment-1214614 Share on other sites More sharing options...
hoponhiggo Posted May 12, 2011 Author Share Posted May 12, 2011 it really is that simple! thank you! Link to comment https://forums.phpfreaks.com/topic/236242-random-records/#findComment-1214687 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.