Jump to content

Archived

This topic is now archived and is closed to further replies.

mazman13

Can I get a random row. with mySQL

Recommended Posts

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.

Share this post


Link to post
Share on other sites
SELECT * from $tablename ORDER by RAND LIMIT 1

Share this post


Link to post
Share on other sites
Wow! thats it? I don't even need that random PHP script huh? it will pick somethin on random huh?

Share this post


Link to post
Share on other sites
Sorry it's so simple, but yes that will pick a single random row without any help from anything else ;D

Share this post


Link to post
Share on other sites
Code works great, just one lil' thing to fix to make it work:
SELECT * FROM $tablename ORDER BY RAND[b]()[/b] LIMIT 1

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.