Okay, what I have done so far is to be able to click on a build button, and have it enter the time you clicked on it in one field in the database, and the time it takes for it to build in another field in the database. So it's set for testing, to 45 minutes. When you click the build, it puts the current time in there and then for the finish time, it takes the current time and adds 45 minutes to it. What I need now is for it to show the timer with the code you gave above. I know nothing about ajax or jquery or anything, so any help would be great. Thank you.
Code:
Code: Select all
<?php
$db_conx = mysqli_connect("localhost", "root", "", "time");
// Evaluate the connection
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit();
}
$time = time();
$sql = "UPDATE time SET start='$time'";
$query = mysqli_query($db_conx, $sql);
?>
<?php
if(isset($_POST['bus'])) {
$sql = "SELECT * from time WHERE userid = 1 LIMIT 1";
$user_query = mysqli_query($db_conx, $sql);
$row = mysqli_num_rows($user_query);
$time = time();
$finish = time() + strtotime($row['start']) + (90 * 30);
$currenttime = $time;
$sql2 = "INSERT INTO time (start, finish) VALUES ($time, $finish)";
$query = mysqli_query($db_conx, $sql2);
}
?>
<?php
$bus="<img src='bus.png'>";
echo " $bus";
?>
<div id="bus">
<table>
<form method='post' action='timerexample.php'>
<td class="tooltip"><input type='submit' value='Build'></td>
<input type='hidden' name='bus' value='1'></form>
</table>
So as an example, in the database it looks like:
Start time: 1395097384
Finish time: 1395100084
Subtract the two, it's 2700 seconds, which is 45 mintues
I could easily just echo the difference to show the remainder, but then it wouldn't countdown; you would need to refresh page in order to see the progress. I need a timer to countdown that 45 minutes and for the build button to be removed while it's counting down, AND where the timer doesn't start over when the page is refreshed.