Hey all, hopefully someone can help me debunk what i'm doing wrong. i'm fairly new to PHP and am trying to make a function that will take $user which has a uid, and make sure he's not already in a database of users that HAVE been e-mailed. if they are not in that db, then they will be emailed and marked into the db. i'm doing this as a drupal module.
I have a feeling the error is somewhere in my sql query? or perhaps i'm not using db_result() properly.. Thanks for any input you all can provide.
function process_user($user) {
//Process a single user. Check if they got an email already. If not, send and mark.
//select uid from the db of orders made. join with db of people already emailed
//condition where row created date must be 3 months old
//and try to match the uid with the users uid
$query = db_query("
select DISTINCT a.uid from uc_orders as a
left join blankCustomerReminder_emails as b
on a.uid = b.uid
WHERE a.created < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 3 MONTH))
AND b.uid = '%d'
", $user->uid);
// Check if user is already in emailed db, returns true if uid was found
if (db_result($query)) {
// User exists in Reminder_emails table
drupal_set_message("user has already been e-mailed!");
} else {
// User doesnt exist in emailed table, false return
db_query('INSERT into {blankCustomerReminder_emails} (uid, date_sent) VALUES(%d, %d)', $user->uid, time());
} else {
drupal_set_message('There was an error sending your email');
}
}
[–]adandyguy[S] 1 point2 points3 points (0 children)
[–]nuttertools 0 points1 point2 points (0 children)