PHP - display 1 random entry per week

I want to display 1 random record from a database based on a week.

I need to determine if this is new, and if it is a new week, then select the entry and display the new entry.

I think I can just use one day of the week to create a new record, it will work anyway.

It’s really difficult for me to understand how I will store the record ID, and not choose a new one when someone visits the same day again or refreshes the page.

Any ideas? Let me know if I was not clear enough.

In addition, I do not have access to cron jobs because it hosted the hosting.

+3
source share
3 answers

, , , datetime/timestamp, , . , , , . , . , cron-, .

+2

script , . script, . , script cron.

script A , script B . , Id recored script A, Id script, .

0

The MySQL function RAND()takes an integer parameter N, which is used as the initial value. This allows you to get the same sequence in multiple queries - you can take a look at the examples at http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_rand . I would try to use something like SELECT field_1, field_2, field_3 FROM table_name ORDER BY RAND($time) ASC LIMIT 1where there $timewill be a UNIX timestamp for the beginning of the current week.

0
source

Source: https://habr.com/ru/post/1742784/


All Articles