×

Please Login or Register to continue.

4
(6.1K Views)

Is there any way that the countdown clock timing can be coded to vary over certain conditions?
(210 Points)
in PHP

Share

3 Answers
(9.4K Points)
(edited)
2

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 hr 

 

30 second countdown timer in JS

Use the JS scripts below to run a 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 a 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>  

 


Comment

(7.3K Points)
(edited)
2

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

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

This solution was posted here - 

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

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


Comment

(9.4K Points)
1

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.

 

 


Comment

Related Questions :-

Featured Items:-


Certificate system in PHP website | PHP scripts

$22



Home Credito loan finance management multipurpose system in PHP

$65



Result management system with Marksheet in PHP website | PHP Scripts

$39




Your Answer

You can post your answer after login..