Search code examples
phpmysqldate-comparison

php mail() statements


I am trying to get all the users information from the database and check the timestamp (fourteendays) and check it with the time now I got the time bit working but I can't get it to send to all the when the time is > fourteendays

 $result1 = mysql_query("SELECT * FROM accounts") or die (mysql_error()); 
 while ($row1 = mysql_fetch_array($result1)) {
 $users_email = $row1['email'];
 $user_name = $row1['user'];
 $days_time = $row1['fourteendays'];
 if($timenow > $days_time){
 mail( $users_email, $subject, $emailbody, $headers);
 echo "email sent!";
 }
 }

Solution

  • I recommend doing the date comparison in SQL, instead of pulling back all of the data in your query:

    SELECT * FROM accounts WHERE DateDiff(Now(), fourteendays) > 14
    

    Also, what is in that column in the database? If it is a timestamp, why don't you just call it as such? Am I missing something?