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. 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. 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() Link to comment https://forums.phpfreaks.com/topic/114472-solved-2-ordery-bys/#findComment-588802 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.