Reputation: 187
How do I go about using AJAX to create a dynamic countdown timer using MySQL and PHP?
Here is a scaled back version of my PHP script that interacts with my MySQL database, but how can I get it to countdown without having to refresh the page?
<?php
$con = mysql_connect("database-server","username","password");
mysql_select_db("database", $con);
$sql = mysql_query("SELECT TIMEDIFF(example_finish, NOW()) FROM example;");
echo "<table>
<tr>
<th>COUNTDOWN_TIMER</th>
</tr>";
while($row = mysql_fetch_array($sql))
{
echo "<tr>";
echo "<td>" . $row["TIMEDIFF(example_finish, NOW())"] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
Any help or pointers would be greatly appreciated. Thanks. :)
Upvotes: 0
Views: 2992
Reputation: 3048
Based on your description I don't see you needing to poll the database other then to set up the initial countdown time.
I have found this link to various implementations of countdown timers.
Upvotes: 1