Advertisement
Guest User

Untitled

a guest
Jan 11th, 2013
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $today   = date('Y-m-d');
  2.  
  3. $query = "SELECT lastdate FROM table_lastdate"; //I made a new table just to save the last date of the login
  4. $result = mysql_query($query);
  5. $last_date = mysql_result($result,0);
  6.  
  7.  
  8. $cur_date = strtotime($today);
  9. $last_date1 = strtotime($last_date);
  10. $difference = (($cur_date-$last_date1)/(60*60*24)); //difference in number of days
  11.  
  12. if($difference>0){ //checks if there are any missing days to avoid duplication
  13.     for($i=1;$i<$difference;$i++){
  14.         $calculated_date = strtotime ("+$i day",strtotime($last_date));
  15.         $newdate = date ('Y-m-d',$calculated_date); //creates a date which is +1 of the last_date
  16.         mysql_query("INSERT INTO table_xyz(date,spent) VALUES('$newdate','0')");
  17.     }
  18. }
  19.  
  20. mysql_query("UPDATE table_lastdate SET lastdate = '$todays_date' WHERE lastdate = '$last_date'"); //updates the last date to todays date
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement