Reputation: 5717
I have written a piece of code that allows an email to be sent out to all users that haven't logged in for a certain amount of time.
The HTML is:
<select name="criteria">
<option value="14"<?php if("14" == $form->value("criteria")){ echo 'selected="selected"'; }?>>14 days</option>
<option value="28"<?php if("28" == $form->value("criteria")){ echo 'selected="selected"'; }?>>28 days</option>
<option value="90"<?php if("90" == $form->value("criteria")){ echo 'selected="selected"'; }?>>3 months</option>
<option value="180"<?php if("180" == $form->value("criteria")){ echo 'selected="selected"'; }?>>6 months</option>
<option value="365"<?php if("365" == $form->value("criteria")){ echo 'selected="selected"'; }?>>1 year</option>
</select>
This is then received in another file and the following code takes over
$time = time() - ($criteria * 0 * 0 * 0);
$q = $admindb->getReminderCustomerEmail($time);
The database query is as follows:
function getReminderCustomerEmail($time){
global $database;
$q = "SELECT email, title, forename, surname FROM ".TBL_USERS." WHERE last_logged <= '$time'";
return mysql_query($q, $database->myConnection());
}
The idea is that if you select 14 days, all users that haven't logged in in the last 14 days will be mailed.
At the moment, this isn't happening, it seems to just message all users.
I think the error must be in the line
$time = time() - ($criteria * 0 * 0 * 0);
Any ideas? Thanks
Upvotes: 0
Views: 41
Reputation: 101594
Any number times zero is always zero.
Are you looking for ($criteria * 86400)
perhaps (to get days) then subtract that value from time()
?
You can also use strtotime
:
strtotime('-' + $criteria + ' day',time());
Upvotes: 2
Reputation: 6919
Wouldn't 0 be subtracted from time() all the time? $criteria is being multiplied by 0...
Upvotes: 1