Jump to content

Problem with time() and sql query


Craig Hopson
 Share

Recommended Posts

hi what is wrong with this script it just sends out 2 emails to every one and sets `warning` to 2 no matter what the members `time` isi would like it to send out email "warning" after 1 month then "delete" after 3 months

$t = time()-2629743;$result = mysql_query("SELECT * FROM members WHERE time < $t AND warning = 0");while($row = mysql_fetch_array($result))  {mysql_query("UPDATE members set warning=1 WHERE id=$row[id]");mailthem($row['email'],"warning" );   } $t = time()-7889231;$result = mysql_query("SELECT * FROM members WHERE time < $t AND warning = 1");while($row = mysql_fetch_array($result))  {mysql_query("UPDATE members set warning=2 WHERE id=$row[id]");mailthem($row['email'],"delete");   }

the main problem i have is getting my head round the output of time() HELP!!!!!Thanks in advance

Edited by Craig Hopson
Link to comment
Share on other sites

That's fine, but it doesn't change the fact that the SQL queries match every record. If you want to find out why then print out the value of $t and loop through the result set to print out each person's value for time. In other words, verify your data and figure out what you're telling MySQL to do to see why it is returning every record.

Link to comment
Share on other sites

no i still cant get what the problem is i changed the code to this for testing

$t = time()-2629743;echo 'time:->>'.$t.'<br>';$result = mysql_query("SELECT * FROM members WHERE time < $t");while($row = mysql_fetch_array($result))  {echo $row['id'].'>>>> '.$row['time'].'<br>';  }echo '<p>';$tt = time()-7889231;echo 'time2:->>'.$tt.'<br>';$result2 = mysql_query("SELECT * FROM members WHERE time < $tt");while($row = mysql_fetch_array($result2))  {echo $row['id'].'>>>> '.$row['time'].'<br>';  }

now the first query shows all and the second query shows the one account thats 4 months old

Link to comment
Share on other sites

time:->>133291404521>>>> 133286760022>>>> 133036200023>>>> 132768360024>>>> 1325005200 time2:->>132765455724>>>> 1325005200 OH SUGAR I SEE NOW IT IS WORKING I'M SO SORRY FOR WAITING YOUR TIME ID 20 is todayID 21 is 1month oldID 22 is 2 months oldand so on.... ID 20 is not shown its to young im sorry buddy thanks for your time

Edited by Craig Hopson
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...