How to make it a function to apply it to a PHP variable?

1
<script>
    jQuery(function($){
        $('#timer').countdown({
            until: new Date("2015-11-04 12:00:00"),
            compact: true
        });
    });
</script>

I need to transform the code above into a function and then apply this function to a PHP variable that is inside a loop. How to do this?

while ( $linha = mysql_fetch_array($query) ) {

     echo $datafinal;           // Y-m-d h:i:s

}
    
asked by anonymous 08.10.2015 / 13:51

1 answer

2

One way to do this is by using AngularJS:

Template with counter: link

Template where you arrow the start and end of the counter: link

Template with jquery: link

I do not think you need to use PHP to create a countdown. You pass the start date and end date, and have a formatting attribute for the output in the view.

    
08.10.2015 / 19:32