Guest User

Untitled

a guest
Sep 27th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. $currentTime = date("Y-m-d H:i:s");
  2.  
  3. // We're looking for the last winner in the winners table
  4. $res = $dbh->query("SELECT date FROM winnertable ORDER BY id DESC")->fetch(PDO::FETCH_ASSOC);
  5.  
  6. if(empty($res)){
  7.     // If there is no last winner then the user wins
  8.     $winner = true;
  9. }else{
  10.     // If there is already a last winner, we check the date of win, if superior to half an hour, the user wins
  11.     if(strtotime($currentTime)-strtotime($res["date"])>=1800){
  12.         // Last winner was half an hour ago : winner
  13.         $winner = true;
  14.     }
  15. }
  16.  
  17. // if the winner flag is set to true, add the user id to the winners table along with the date of winning
  18. if($winner){
  19.     $dbh->query("INSERT INTO winnertable (id_main, date) VALUES ('".$_SESSION['id']."', '".$currentTime."')");
  20. }
Advertisement
Add Comment
Please, Sign In to add comment