How to create a timer

0 votes

Using mysqli the $dbSessionDuration variable can bind the result of data from the query into this variable.  The $dbSessionDuration variable holds time so the variable has a time format as below:

01:30:10

I want to display $dbSessionDuration value in a timer so that in the above's example it will start ticking down from 01:30:10 and go all the way to 0 when it stops.  Can someone tell me how I can create a timer and place whatever value $dbSessionDuration value in the timer to count down to 00:00:00?

May 30, 2022 in PHP by Kichu
• 19,040 points
551 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

What you have to do is, convert your time into seconds.

<?php

list($hour,$min,$sec) = explode(':', $dbSessionDuration);
$dbSessionDurationTime = mktime(0,0,0,$hour,$min,$sec);

?>

To create a countdown, use Javascript.

<script type="text/javascript">
    var millis = <?php echo $dbSessionDurationTime; ?>

    function displaytimer(){
        var hours = Math.floor(millis / 36e5),
            mins = Math.floor((millis % 36e5) / 6e4),
            secs = Math.floor((millis % 6e4) / 1000);
            //Here, the DOM that the timer will appear using jQuery
            $('.count').html(hours+':'+mins+':'+secs);  
    }

    setInterval(function(){
        millis -= 1000;
        displaytimer();
    }, 1000);

</script>

I hope this helps you.

answered May 30, 2022 by narikkadan
• 63,600 points

edited Mar 5

Related Questions In PHP

0 votes
1 answer

What is a Cookie? How to create Cookies With PHP?

A cookie is often used to identify ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,840 points
3,967 views
0 votes
1 answer

How to create a database from shell command?

Hello @kartik, Try: cat filename.sql | mysql -u username ...READ MORE

answered Aug 26, 2020 in PHP by Niroj
• 82,840 points
1,478 views
0 votes
1 answer

How to create and download a csv file from php script?

Hello @kartik, You can use the built in fputcsv() for ...READ MORE

answered Oct 27, 2020 in PHP by Niroj
• 82,840 points
7,404 views
0 votes
1 answer

How to create a database using PDO in PHP?

Hello @Hitesh, Yes, you can create a database using ...READ MORE

answered Nov 9, 2020 in PHP by Niroj
• 82,840 points
6,712 views
0 votes
0 answers

PHP - how to create a newline character?

I am working on creating a newline character: echo $clientid; echo ...READ MORE

Jun 10, 2022 in PHP by narikkadan
• 63,600 points
344 views
0 votes
0 answers

How to create a JSON object

I want to create a JSON object ...READ MORE

Jun 16, 2022 in PHP by narikkadan
• 63,600 points
474 views
0 votes
1 answer

Uncaught TypeError: Cannot read property 'msie' of undefined - jQuery tools

Hello, Use the following script tag in your ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,840 points
16,627 views
0 votes
1 answer

Uncaught Error: Bootstrap's JavaScript requires jQuery

Hello @kartik, You have provided wrong order for ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,840 points
23,899 views
0 votes
1 answer

How to make Bootstrap popover Appear/Disappear on hover instead of click?

Hello @kartik, Set the trigger option of the popover to hover instead ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,840 points
3,595 views
0 votes
1 answer

How to enable Bootstrap tooltip on disabled button?

Hii @kartik, You can wrap the disabled button ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,840 points
5,384 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP