Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please I need help to display Javascript Countdown with PHP to my screen, i've already create Mysql table.

Please I need your help.

What I have tried:

<pre><?php


//including the database connection file
include("config.php");

$conn= mysqli_connect("localhost", "root", "", "live");

$result = mysqli_query($mysqli, "SELECT * FROM timer ORDER BY id DESC");
while($res = mysqli_fetch_array($result)) { 
$date = $res['date'];
$h = $res['h'];
$m = $res['m'];
$s = $res['s'];
}

if(isset($_POST['submit'])){

    echo "
    <p id='demo'>
<script>
var countDownDate =  * 1000;
var now =  * 1000;

// Update the count down every 1 second
var x = setInterval(function() {
now = now + 1000;
// Find the distance between now an the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Output the result in an element with id='demo'
document.getElementById('demo').innerHTML = days + 'd ' + hours + 'h ' +
minutes + 'm ' + seconds + 's ';
// If the count down is over, write some text 
if (distance < 0) {
clearInterval(x);
document.getElementById('demo').innerHTML = 'EXPIRED';
}
   
}, 1000);

   </script></p>
";}




?>
Posted
Comments
Member 15627495 31-Jul-22 3:04am    
Hello,

what is the aim ?
- launching a timer from the server starting on on a client request ?
- or operating a sync between server timer and client display ?

look at 'Ajax' tool, It's a good way to launch features from a server.
It's asynchronous call of the server,
so the display keeps on, and a timer can exists without reloading the page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900