What I'm using for my game to time building (ie: the player starts constructing a building, it sets a timer, when its done it builds it) is using a few variables that get:
1. The current time
2. the done time (current time+something)
What you will need to do is make an if statement checking if the link or whatever has been clicked, and if it has, then write the current time into 1 field, then the finish time into another. Then check if the current time is equal to or greater than the current time... The only way to execute it though is by refreshing..
Heres an example, it needs alot of modding if you want it per user, but it works for just testing..
Code: Select all
<?php
$time = date(i);
$time1 = $time+2;
$link = mysql_connect("localhost", "***", "***")
or die("Could not connect");
mysql_select_db("your_database", $link) or die("Could not select database");
$query = MYSQL_QUERY("SELECT * FROM time");
while ($fetch=mysql_fetch_array($query)) {
$cur = $fetch[current];
$sta = $fetch[stamp];
echo "Time it was clicked: $fetch[stamp]<br>
Time it is done: $fetch[current]<br>
Current time: $time<br>";
}
if($cur == $time or $time > $cur) {
$aa = "DELETE FROM time";
$bb = mysql_query($aa);
echo "Done<br>";
} else{
$aa4 = $cur-$time . " minute(s) left.";
echo $aa4."<br>";
}
echo "<a href=aa.php?up=yes>GGOGOGOGO</A>";
if($up == "yes") {
mysql_query("INSERT INTO time (tid, stamp, current) VALUES ('', '$time', '$time1')", $link) or die("Could not select database");
}
?>
Just keep in mind you would need some more fields like username, and its not really structured in the way you may want, just an example... if you want to test it set up a table called time with the fields tid, stamp, current and make sure tid is auto increment..