alwoodman Posted February 23, 2009 Share Posted February 23, 2009 I have this query, its a bit more complex than what's written below but it returns over 1000 rows of data and on using ORDER BY RAND() is hundreds of time slower than the other queries running in the system. I want to remove the ORDER BY RAND() function which will return 3 results. I then want to run another query with a specific ID from the returned results set. Will this speed up the query as its not using ORDER BY RAND(). I guess what im trying to say is how do i randomly select a row from a results set? mysql_select_db($database_system_conn, $system_conn); $query_getFeaturedBusiness = "SELECT ID FROM Business WHERE Status = 1 ORDER BY RAND()"; $getFeaturedBusiness = mysql_query($query_getFeaturedBusiness, $system_conn) or die(mysql_error()); $row_getFeaturedBusiness = mysql_fetch_assoc($getFeaturedBusiness); $totalRows_getFeaturedBusiness = mysql_num_rows($getFeaturedBusiness); thanks Lee Link to comment https://forums.phpfreaks.com/topic/146509-order-by-rand-alternative/ Share on other sites More sharing options...
rhodesa Posted February 23, 2009 Share Posted February 23, 2009 mysql_select_db($database_system_conn, $system_conn); $query_getFeaturedBusiness = "SELECT ID FROM Business WHERE Status = 1"; $getFeaturedBusiness = mysql_query($query_getFeaturedBusiness, $system_conn) or die(mysql_error()); $totalRows_getFeaturedBusiness = mysql_num_rows($getFeaturedBusiness); mysql_data_seek($getFeaturedBusiness,rand(0,$totalRows_getFeaturedBusiness)); $row_getFeaturedBusiness = mysql_fetch_assoc($getFeaturedBusiness); Link to comment https://forums.phpfreaks.com/topic/146509-order-by-rand-alternative/#findComment-769175 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.