views:

57

answers:

4

Hello i am trying to get all the users infomation 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!";
 }
 }

Thank you.

+1  A: 

Try. Thats greater than or equal to 14 days.

 if($timenow >= $days_time){
     mail( $users_email, $subject, $emailbody, $headers);
    echo "email sent!";
 }

Also SELECT * is bad practice. You should only select the fields you need in that query.

Ben Shelock
SELECT * isn't that bad compared to selecting rows you don't actually need.
MarkR
+3  A: 

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?

Justin Ethier
yes its a timestamp
Gully
You may want to consider calling it "EmailTime" or something more intuitive. Were you able to get this to work using an updated SQL statement?
Justin Ethier
A: 

I assume you have already set the '$timenow' variable somewhere previous in the script and I would make sure to check that both time formats are the same when comparing. That was my problem in the past.

For date-related php information, visit the following link

http://ca.php.net/manual/en/function.date.php

ceneko
A: 

Or even

SELECT * FROM accounts WHERE fourneendays < (NOW() - INTERVAL 14 DAYS);

I am assuming that NOW() gives the timestamp you want - it won't be in UTC (But you knew that, right)?

MarkR