-3

I have a MySQL database with 112 rows (with ID column from 1 to 112), I need to SELECT 6 random rows (doesn't matter if sequential) to show in PHP/HTML page and to be changed daily. The only option I think is to depend on the current date. Is there any solution ?!

Thank you ...

EDIT: Question was solved. Although no one really understood what I want but I keep getting down votes.

The question was : 6 Random rows EVERY DAY not every page refresh or every call from DB.

But thanks for the amazing effort. Question solved.

Tariq
  • 59
  • 6

3 Answers3

2

The MySQL statement ORDER BY RAND() will order the matching rows randomly. Combined with LIMIT 6 you'll get six random rows.

See http://dev.mysql.com/doc/refman/5.7/en/mathematical-functions.html#function_rand for reference.

Janek
  • 2,942
  • 1
  • 14
  • 14
2

Just use ORDER BY RAND() to randomize the row order, then show the first 6:

SELECT * FROM Yourtable ORDER BY RAND() LIMIT 0,6;
dr_
  • 2,400
  • 1
  • 25
  • 39
1

Use following query

SELECT column FROM table
ORDER BY RAND()
LIMIT 6
Don Srinath
  • 1,565
  • 1
  • 21
  • 32