How to cound with PHP and print resulsts live according to current time? For example, here is my PHP code. I get number, changing every second. $now=date("Y-m-d H:i:s"); $now_seconds = strtotime( "$now" ); $time_ago_seconds = strtotime( "$my_time_from_database" ); $diference_in_seconds = $now_seconds - $time_ago_seconds; Code (markup): How is it posible to see real time counting results without refreshing page? Should I use mootools, prototype or something else? P.S. I've no knowledge in JS or AJAX.
Try follow: <?php $now=date("Y-m-d H:i:s"); $now_seconds = strtotime( "$now" ); $time_ago_seconds = strtotime( "$my_time_from_database" ); $diference_in_seconds = $now_seconds - $time_ago_seconds; ?> <html> <head> <script type="text/javascript"> var diference_in_seconds = <?php echo($diference_in_seconds); ?>; var t; function timedCount(){ document.getElementById('seconds').innerHTML = diference_in_seconds; diference_in_seconds = diference_in_seconds + 1; t = setTimeout("timedCount()",1000); } </script> </head> <body> <div id="seconds"></div> </body> <script>timedCount();</script> </html> Code (markup):
OMG... Thank you so much! It's working perfectly. After a lot of asking this thing in various forums at least I get it working. Now it's pretty easy to edit main features and make that I need. Thank you again.