Why won't this work? I am trying to send a message for each record that is close to expiration (based on expiration date). When I run the query on the DB, I get the correct results (2 records), but when this is executed in the script, I get two messages sent for the same record. It is only getting the title, mls, date_expired for the first record that is returned in the query instead of having two distinct messages sent.
LJ Wilson
My personal saying - Just remember, it can always get worse, and usually will.
Code:
$sql = 'SELECT id FROM ' . PROPERTIES_TABLE . ' WHERE userid = 28 AND active = 1 AND ( ( TO_DAYS(NOW()) - TO_DAYS(date_expired) ) <= 10)';
$r = $db->query($sql) or error ('Critical Error', mysql_error ());
while ($f = $db->fetcharray($r))
{
$sql = 'SELECT * FROM ' . PROPERTIES_TABLE . ' WHERE id = ' . $f['id'];
$re = $db->query($sql) or error ('Critical Error', mysql_error ());
$fe = $db->fetcharray($re);
$sql = 'SELECT * FROM ' . USERS_TABLE . ' WHERE id = ' . $fe['userid'];
$ru = $db->query($sql) or error ('Critical Error', mysql_error ());
$fu = $db->fetcharray($ru);
// Start a new email
$mailout = new Mailer;
// From
$mailout->from($conf['general_e_mail'], $conf['general_e_mail_name']);
// To
$mailout->add_recipient($fu['email']);
// Subject
$mailout->subject($lang['Listing_Expiration_Subject']);
$lang['Listing_Expiration_Email'] = str_replace('{name}', $fu['first_name'] . ' ' . $fu['last_name'] , $lang['Listing_Expiration_Email']);
$lang['Listing_Expiration_Email'] = str_replace('{listing}', $fe['title'], $lang['Listing_Expiration_Email']);
$lang['Listing_Expiration_Email'] = str_replace('{mls}', $fe['mls'], $lang['Listing_Expiration_Email']);
$lang['Listing_Expiration_Email'] = str_replace('{date}', printdate($fe['date_expired']), $lang['Listing_Expiration_Email']);
$lang['Listing_Expiration_Email'] = str_replace('{website}', $conf['website_name'], $lang['Listing_Expiration_Email']);
$mailout->message($lang['Listing_Expiration_Email']);
$mailout->send();
}
LJ Wilson
My personal saying - Just remember, it can always get worse, and usually will.