I'm having a lot of trouble wrapping my brain around how to do this.
I have a database table with player information in it (Name, socialmedia handle, photo). I have a module where I want to display one player in that module randomly. Now if I just use:
$pQuery = "SELECT * FROM `players` ORDER BY RAND() LIMIT 1";
It'll pick a random player every time the page is refreshed.
I want to write something where it will display a new random player once a day. No matter how many times you refresh the page (as long as it is the same day), it will always show that one player. As soon as 12midnight (in my time zone, of course) strikes, it queries the table again and displays a different random player.
I'm trying to understand if setting up a SQL Event is the solution, but I'm not experienced enough in MySQL to understand how those work. I've also read that maybe a Cronjob is the solution.
I've been googling for days now and haven't been able to find a solution that I can wrap my brain around, so I'm hoping someone can point me in the right direction.
Thank you in advance.
RAND(seed)) , whereseedis equivalent to the current date, such as days since epoch, which effectively means you get the sameRANDresult for the whole day.RAND()query literally once when you want it and persist the ID to a static location.