lilman Posted December 5, 2006 Share Posted December 5, 2006 My objective: To fetch the results of the query and then put the results into a numeric array. Then I will use the rand() function to randomly select a number and display that array value. My mysql code is below:[code]$cat=$column['category'];$smiliarpolls="SELECT * FROM polls WHERE category='$cat'";$run=mysql_query($smiliarpolls);[/code]I want to display 10 random polls that meet the criteria above. Any ideas? Thank you Link to comment https://forums.phpfreaks.com/topic/29483-put-mysql-rows-in-a-numeric-array/ Share on other sites More sharing options...
drifter Posted December 5, 2006 Share Posted December 5, 2006 EDIT: SHOOT - I answered for one random poll... (do a while loop and array push - will give you all them in an array - then do a shuffle and take the first 10)there is an order by rand in mysql, however it is kinda slow.if you know you have at least 20 polls in there, you can $num=rand(0,19) (get random number)ORDER BY id DESC (to get the most recent)LIMIT $num,1That would get you a random out of your last 20Or do two queries one with a count and then choose random from that number. but that i a bit slower again.hope this helps... Link to comment https://forums.phpfreaks.com/topic/29483-put-mysql-rows-in-a-numeric-array/#findComment-135296 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.