MySQL’s rand() Statement Is A Life-Saver

>> Original Post @ KilerMedia.com <<

So, recently I've been working very hard on a TGP system of sorts...as you may already know. Well, I was trying everything to figure out how to get the listings in a MySQL database to "re-position" themselves, or using a better term, "rotate". And, I did it! This was actually extremely simple compared to a lot of other techniques I was trying out to tackle the problem. And what a solution it is!

MySQL has an embedded command to use for randomly selecting a row(s) from the database, straight from the command line. It was this wonderful command that saved me many hours, if not days, of development and tinkering time. I LOVE YOU rand()!! Here is the just of my discoveries:

Basic syntax:

SELECT column FROM table
ORDER BY RAND()

Now, I’m not going to just give out gimmies here so you’ll have to use your own brain and figure out how to use the rand() command to produce a ranking system! Enjoy!

Spread The Word: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • Technorati
  • StumbleUpon
  • Slashdot
  • Reddit
  • Spurl
  • Live
  • YahooMyWeb
  • e-mail

Leave a Reply

You must be logged in to post a comment.