So i have read and doing some example of the countdown timer but i still didn't have a clear idea about how to create a count down timer. I want do a countdown timer which is countdown 7 days when the countdown end will echo a div with top post in this week. The div will stay there and the timer will be restart again with 7days and after 7 days will echo the new weekly top post. and again and again. before i was using js to do this with a simple timer but when refreshing broswer the timer will restart. And i know there have local storage but when user delete cookie the timer will restart again. i want it to be the same with every user. what should i do? does anyone can give me a clear idea or step to develop this?
currently i was thinking a way to do this is using sql to compare the starttime and endtime when reach to the endtime echo div and content and +7days to the end time and store the current time to start time and repeat it and repeat it <
i have do a simple php script with mysql and using jq to make the time running every second
here is my countdown.php << i cant using $today compare with $end which is select out from db so i was create it a new $ending to compare
<?php
include '../config.php';
date_default_timezone_set('Asia/Kuala_Lumpur');
$today = date("Y-m-d H:i:s");
$s="Select TIMESTAMP(start_date)as date_field from countdown_timer";
$e ="Select TIMESTAMP(end_date)as date_field from countdown_timer";
$start = mysqli_query($connection,$s)or die(mysqli_connect_errno($connection));
$end = mysqli_query($connection,$e)or die(mysqli_connect_errno($connection));
$ending = date("2016-06-01 23:05:40");
if ( $today == $end ){
echo "abc";
$next_seven_date= date('Y-m-d H:i:s', strtotime($today. ' + 1 minute'));
$end_add_time = mysqli_query($connection,"INSERT INTO countdown_timer (`end_date`) VALUES ('$next_seven_date') ");
}
else {
echo "$today";
}
this is my jq to make the timer running every second
$(document).ready(function(e){
$.ajaxSetup({cache:false});
setInterval(function(){$('#countdown').load('countdownTimer.php?');}, 1000);
});
this is my html
<div id="countdown"></div>
I have a hard time with this hope there have a way to develop this