mazman13 Posted September 14, 2006 Share Posted September 14, 2006 Ok, I have a script that picks a random number based on the number of banners in my database.The number is used to pick a rank number in the banners.example: random number 1, so it picked picture.jpg (rank no. 1) from the database and plays it.Is there a way, to just have it pick a row number. example: SELECT * FROM database WHERE COL NUMBER IS (random number from script)cuz the way i have it now, if i erase a banner now, the image rank is erased, so some banners might now be picked. can i get info from a row number? i hope people can understand what i'm saying...ask questions if you don't understand...i havn't slept much this week. Link to comment https://forums.phpfreaks.com/topic/20802-can-i-get-a-random-row-with-mysql/ Share on other sites More sharing options...
AndyB Posted September 14, 2006 Share Posted September 14, 2006 SELECT * from $tablename ORDER by RAND LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/20802-can-i-get-a-random-row-with-mysql/#findComment-92080 Share on other sites More sharing options...
mazman13 Posted September 14, 2006 Author Share Posted September 14, 2006 Wow! thats it? I don't even need that random PHP script huh? it will pick somethin on random huh? Link to comment https://forums.phpfreaks.com/topic/20802-can-i-get-a-random-row-with-mysql/#findComment-92082 Share on other sites More sharing options...
AndyB Posted September 14, 2006 Share Posted September 14, 2006 Sorry it's so simple, but yes that will pick a single random row without any help from anything else ;D Link to comment https://forums.phpfreaks.com/topic/20802-can-i-get-a-random-row-with-mysql/#findComment-92083 Share on other sites More sharing options...
mazman13 Posted September 15, 2006 Author Share Posted September 15, 2006 Code works great, just one lil' thing to fix to make it work:SELECT * FROM $tablename ORDER BY RAND[b]()[/b] LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/20802-can-i-get-a-random-row-with-mysql/#findComment-92477 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.