joecooper Posted August 8, 2007 Share Posted August 8, 2007 Which command can i use which will return a random row from mysql? At the moment, this will return the lastest added row with ID as DESC: $sql=mysql_query('SELECT * FROM wallpapers ORDER BY ID DESC LIMIT 1'); but i need just a random row from it Quote Link to comment https://forums.phpfreaks.com/topic/63975-solved-random-row/ Share on other sites More sharing options...
lemmin Posted August 8, 2007 Share Posted August 8, 2007 You can use PHP's random function and use the number as a row id. $sql=mysql_query("SELECT * FROM wallpapers WHERE ID = " . rand(min, max)); Quote Link to comment https://forums.phpfreaks.com/topic/63975-solved-random-row/#findComment-318885 Share on other sites More sharing options...
joecooper Posted August 8, 2007 Author Share Posted August 8, 2007 ah, the min and max is what i cant enter. they are updated all the time so i cant exactly keep check on how many rows there are. i COULD how ever use the min as 0, and max as the ID number, but again when rows are deleted... Quote Link to comment https://forums.phpfreaks.com/topic/63975-solved-random-row/#findComment-318890 Share on other sites More sharing options...
joecooper Posted August 8, 2007 Author Share Posted August 8, 2007 for those who may be looking for answer for this: use ORDER BY RAND() Quote Link to comment https://forums.phpfreaks.com/topic/63975-solved-random-row/#findComment-318899 Share on other sites More sharing options...
teng84 Posted August 8, 2007 Share Posted August 8, 2007 you answer your question LOL so mark it solved Quote Link to comment https://forums.phpfreaks.com/topic/63975-solved-random-row/#findComment-318913 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.