ohdang888 Posted July 12, 2008 Share Posted July 12, 2008 I have a list, and i want to order by `bid` DESC and LIMIT 4, and then i want to order those 4 by random? how do i do that? SELECT `id`, `format` FROM `test` WHERE `cat`='$cat' ORDER BY `bid` DESC LIMIT 4 rand() Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/114472-solved-2-ordery-bys/ Share on other sites More sharing options...
ratcateme Posted July 12, 2008 Share Posted July 12, 2008 once you do that query you should put all the results into a array like this <?php $rs = mysql_query("SELECT `id`, `format` FROM `test` WHERE `cat`='$cat' ORDER BY `bid` DESC LIMIT 4"); $rows = array(); while($row = mysql_fetch_assoc($rs)){ $rows[] = $row; } shuffle($rows); ?> the shuffle will randomize the 4 rows. Scott. Quote Link to comment https://forums.phpfreaks.com/topic/114472-solved-2-ordery-bys/#findComment-588607 Share on other sites More sharing options...
sasa Posted July 13, 2008 Share Posted July 13, 2008 SELECT * FROM (SELECT `id`, `format` FROM `test` WHERE `cat`='$cat' ORDER BY `bid` DESC LIMIT 4) ORDER BY RAND() Quote Link to comment https://forums.phpfreaks.com/topic/114472-solved-2-ordery-bys/#findComment-588802 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.