Welcome to Techno Smarter QA, Questions, Answers Community
+4 votes
36 views
Is there any way that the countdown clock timing can be coded to vary over certain conditions?
in PHP by (210 points) 6

3 Answers

+2 votes

You can use JS. JS (Java scripts) helps in the countdown clock timer to set seconds with HTML. Create a function "function countDown" between script tags and define the countdown clock timer seconds. You can set a countdown clock timer for any seconds. 

Like - 

A countdown clock timer for 30 seconds 

A countdown clock timer for 10 seconds 

Countdown clock timer for 1 minute 

A countdown clock timer for 1 hrs 

30 second countdown timer in JS

Use the JS scripts below to run countdown timer for 30 seconds. 

<script>

function countDown(secs,elem) {

var element = document.getElementById(elem);

element.innerHTML = "Timer: "+secs+" seconds";

if(secs < 1) {

clearTimeout(timer);

element.innerHTML = '<h2>Ended</h2>';

element.innerHTML += '<a href=" ">Reset</a>';

}

secs--;

var timer = setTimeout('countDown('+secs+',"'+elem+'")',1000);

}

</script>

<div id="status"style="font-size:30px;"></div>

<script>countDown(30,"status");</script> 

It's a better way to use CSS with countdown timer in JS. You can design it with any design by CSS. After a  completed the time, you can reset the countdown clock timer again for 30 seconds. 

Countdown timer in JS | Ended clock timer

Set any seconds in this line of countdown clock timer in Javascript. 

<script>countDown(30,"status");</script> 

You can use a PHP script to change this countdown timer seconds. Insert value in the MYSQL database and fetch (retrieve ) using PHP and MYSQL database. 

Save that value in a PHP variable.

Use the PHP variable in the line below. 

<script>countDown(30,"status");</script>  

by (7.7k points) 5 22 56
How can the timer be coded to reset automatically?
+2 votes

Thanks for posting your question. I am here to help you. You are looking for countdown timer in PHP and want to know, how to create a countdown clock timer in PHP with MYSQL database.

var seconds = Math.floor((distance % (1000 * 60)) / 1000); 

This solution was posted here - 

You can create a complete countdown timer and set for any time for seconds, minutes and hrs from the admin panel in PHP. 

How to create countdown timer using JS, PHP and MYSQL database?

by (5.4k points) 5 23 53
+1 vote

A clock countdown timer can be created with JS but if you want to update it using PHP then follow the steps below. 

1. Create an MYSQL database. 

2. Insert data into MYSQL table 

3. Fetch data from the MYSQL database using PHP. 

4. Store value in a PHP variable. 

5. Use that value in the countdown function of JS for 30 seconds timer. 

Let's have a look. 

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

<?php 

$phpvar="30"; 

?> 

<script>

function countDown(secs,elem) {

var element = document.getElementById(elem);

element.innerHTML = "Timer: "+secs+" seconds";

if(secs < 1) {

clearTimeout(timer);

element.innerHTML = '<h2>Ended</h2>';

element.innerHTML += '<a href=" ">Reset</a>';

}

secs--;

var timer = setTimeout('countDown('+secs+',"'+elem+'")',1000);

}

</script>

<div id="status"style="font-size:30px;"></div>

<script>countDown(<?php echo $phpvar; ?>,"status");</script>

</body>

</html>

You can set any value of the PHP variable.  

30 seconds countdown timer in JS and PHP. 

<?php 

$phpvar="30"; 

?> 

10 seconds countdown clock Timer in JS and PHP 

<?php 

$phpvar="10"; 

?> 

You can use this JS script before downloading any file from the server.

by (7.7k points) 5 22 56
...