ohdang888 Posted December 24, 2007 Share Posted December 24, 2007 hey. i am creating a gaming site. in one section, it will display related games... first of all, wahts the easiest way to do that?i'm thinking MYSQL might be the only way... when i get the results, i want it to pick 5 random ones and put them in a random order. any1 no the outline of that kind of code? Quote Link to comment https://forums.phpfreaks.com/topic/83003-solved-randomizing-results/ Share on other sites More sharing options...
p2grace Posted December 24, 2007 Share Posted December 24, 2007 Return the items from the db into an array. Then use: shuffle($array); $new_array = array(); for($i=0;$i<5;$i++){ $new_array [] = $array[$i]; } Quote Link to comment https://forums.phpfreaks.com/topic/83003-solved-randomizing-results/#findComment-422175 Share on other sites More sharing options...
trq Posted December 24, 2007 Share Posted December 24, 2007 This can all be done in your query.... SELECT game FROM games ORDER BY RAND(id) LIMIT 5 Quote Link to comment https://forums.phpfreaks.com/topic/83003-solved-randomizing-results/#findComment-422178 Share on other sites More sharing options...
ohdang888 Posted December 26, 2007 Author Share Posted December 26, 2007 thorpe. i tried your way. this is what i am getting back.... Unknown column 'id' in 'order clause' this is my full query $result = mysql_query("SELECT * FROM test ORDER BY RAND(id) LIMIT 5") what am i doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/83003-solved-randomizing-results/#findComment-423582 Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 Replace id with whatever your id field name is. Quote Link to comment https://forums.phpfreaks.com/topic/83003-solved-randomizing-results/#findComment-423588 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.