Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $currentTime = date("Y-m-d H:i:s");
- // We're looking for the last winner in the winners table
- $res = $dbh->query("SELECT date FROM winnertable ORDER BY id DESC")->fetch(PDO::FETCH_ASSOC);
- if(empty($res)){
- // If there is no last winner then the user wins
- $winner = true;
- }else{
- // If there is already a last winner, we check the date of win, if superior to half an hour, the user wins
- if(strtotime($currentTime)-strtotime($res["date"])>=1800){
- // Last winner was half an hour ago : winner
- $winner = true;
- }
- }
- // if the winner flag is set to true, add the user id to the winners table along with the date of winning
- if($winner){
- $dbh->query("INSERT INTO winnertable (id_main, date) VALUES ('".$_SESSION['id']."', '".$currentTime."')");
- }
Advertisement
Add Comment
Please, Sign In to add comment