我如何每隔30天从我的MySQL数据库中显示一个随机行? [关闭]

I am working on my members system and I want to display a "Featured Member" in the sidebar every 30 days, I want the selection to be random. Any ideas? Tips?

EDIT: I understand how to query the database to display a random row, I was wondering what I would have to do to display the data every 30 days

This is actually 2 questions:

~ get a random member

~ display a member for 30 days

The first part can be done using the SQL query from JW or by a range of other query methods.

The second part has to be done using PHP. There are a number of ways to do this and the most interesting part of your problem to me is changing it every 30 days.

Personally I'd either a cron job or use one a solutions based around whatever month it is and storing the random member with reference to that month stamp. If the month stamp changed the random member stored changes. Something like that.

  1. create a db table to store the current, and possibly the past picks
  2. create a cron job that runs every 30 days
  3. populate the table, taking in to consideration who was picked in the past
  4. profit ! :-)

--use the table to select and show as appropriate.

SELECT * FROM Members ORDER BY Rand() LIMIT 1

That is all. You could do a cron job to run this query every 30 days.