2

I'm looking to use this countdown timer

http://keith-wood.name/countdown.html

but I need it to countdown until a specific time from a time entered in a MySQL database. The time is in 23:00:00 format

Here is what I have so far. Just don't know how to plug the time into the JavaScript.

<?php

include('function.php');
$data = mysql_query("SELECT * FROM lockpick WHERE date= CURDATE()");
$row = mysql_fetch_row($data);
$EndTime = $row['EndTime'];
?>

<script type="text/javascript">
    $(function() {
        var austDay = new Date();
        austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);
        $('#defaultCountdown').countdown({until: austDay});
        $('#year').text(austDay.getFullYear());
    });
</script>

2 Answers 2

2

Create a hidden div and load your PHP var into it on pageload. Call it something like #countTo - set it to display:none; in the CSS so it isn't visible.

Access the contents of that div with:

var countTo = document.getElementById("countTo").innerHTML;

Then you can use it all you want!

Sign up to request clarification or add additional context in comments.

Comments

0

I would consider getting value using ajax call. If you do not want to do that you can get value of end time like that

    <script>
        var endTime = <?php 
        include('function.php');
        $data = mysql_query("SELECT * FROM lockpick WHERE date= CURDATE()");
        $row = mysql_fetch_row($data);
        echo $row['EndTime'];
        ?>;
..continue script
    </script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.