I'm trying to setup a Cron Job where it will select a featured video in sequence.
So for example, Video ID 1 is currently the featured video. In a weeks time it will be ID 2. I would then like to load videos 3-18 in after that.
Is this possible using Active Record or an MySQL Statement?
This is quite a hard question to explain, So if you need more info please just comment and I'll get back to you.
Much appreciated.
I agree with @Daan's comment.
Add a new column in your database ( current_featured_id
), it could be TINYINT
with default value of 0. If a video is featured the row will have a 1 in the current_featured_id
column.
In terms of the actual cron job, add in your crontab a command to run the function once a week * 0 * * 0 featured_vid
(runs every Sunday at midnight)
function featured_vid() {
//get the current featured id
$featured_id = $this->db->select('video_id')
->from('table_name')
->where('current_featured_id',1)
->get()->row()->video_id;
$new_featured_id = $featured_id+1;
$update_featured = array(
array(
'video_id' => $featured_id,
'current_featured_id' => 0
),
array(
'video_id' => $new_featured_id,
'current_featured_id' => 1
),
);
//update your db
$this->db->update_batch('table_name', $update_featured, 'video_id');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.