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' Quote 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 Quote 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! Quote Link to comment https://forums.phpfreaks.com/topic/236242-random-records/#findComment-1214687 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.