Answer the question
In order to leave comments, you need to log in
How to create a sql query, php script to raise posts up the list?
Good day to all !
There is such a task:
It is
required to write a script in php to raise up the list of certain posts/records after a certain amount of time (every 4 hours).
Every four hours, a php script will be called using cron.
The script should raise up those posts whose "auto_up" field is equal to "true".
Answer the question
In order to leave comments, you need to log in
Keep three fields in the database: auto_up, created, effective
- the last two are the same when created - the date and time of the post creation.
Every 5 minutes , compare the current time with effective
y records, where auto_up=1
- and if the difference is more than 4 hours, subtract 4 hours from effective
.
When displaying ads, sort by created
, not by effective
.
Maybe you don't need any scripts? Surely posts are sorted by creation time, let this create_time field in the database, then just add the auto_up field to the order by:
...
order by auto_up, create_time desc
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question