Z
Z
Zhandev2016-03-12 10:35:57
PHP
Zhandev, 2016-03-12 10:35:57

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

3 answer(s)
S
Sergey Sokolov, 2016-03-12
@Zhandev

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 effectivey 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.

R
res2001, 2016-03-12
@res2001

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

True, it will be more like freezing posts, and not raising.
By what principle will you cancel the raising of posts? If you do not cancel soon, all the first pages will be taken up by your raised posts.
If the option above doesn't work, add an up_time field, with a default value of create_time. In the lifting script, set this field to the current date/time, and when selecting posts, just like in the example above, add this field to the order by list.

N
nozzy, 2016-03-12
@nozzy

update your_table
set level = 2;

update your_table
set level = 1,
set auto_up = false
where auto_up = true;

select * from your_table
order by level, date_created;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question