Forum Moderators: coopster

Message Too Old, No Replies

Is there a rand() function for mysql?

         

twist

8:13 pm on Apr 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$query = "SELECT item FROM database WHERE item_name = '$name' LIMIT 1";

Okay, the above query will return the first instance of item where it matches item_name. Is there a way to return a single random result using a query.

I could always grab the whole list and then randomly pick one out using php but I would like to cut my query short.

coopster

8:16 pm on Apr 9, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



$query = "SELECT item FROM database WHERE item_name = '$name' ORDER BY RAND() [dev.mysql.com] LIMIT 1";

twist

9:41 pm on Apr 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I know it sounds like a bump, but I just want to say how much I appreciate a quick reply, thanks coopster

coopster

12:40 am on Apr 10, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You're welcome. There's usually somebody lurking around in this forum though. It's not often you see a thread sit for any length of time unless the issue is a code dump or unclear and requiring more information. Specific questions are always welcome -- and yours was quite specific -- so I guess I'll thank you as well :)