• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Getting something random out of mysql ?

jvv

New Member
I'm trying to grab a random article out of a mysql database, and the article must match certain search criteria (ie. not be older than 7 days and match a lookup number 1,2 or 3 which tells if the article is to be a main article, sub or just the title has to be displayed)...

I need to know if there is a relatively easy way to pull something random out of the DB answering to the search criteria...
 
If you (or your host) are running MySQl 3.23+ then you can use the following SQL for fetching a random row of a table (say X) :

select * from X order by rand() limit 1
 
Back
Top