MySQL & PHP: Send emails to the members who fall into last 3 active threads -


my query below last 3 active threads blog's commnets,

select id, approved, recipientid, recipientscreenname, recipientemail ( select  root_strings.str_id id, root_strings.str_approved approved, root_strings.mem_id recipientid,  root_members_cfm.mem_screenname recipientscreenname, root_members_cfm.mem_firstname recipientfirstname, root_members_cfm.mem_email recipientemail  root_strings  left join root_members_cfm on root_members_cfm.mem_id = root_strings.mem_id  root_strings.parent_id = '1'  , root_strings.mem_id not null  union  select root_strings.str_id id, root_strings.str_approved approved, root_strings.mem_id recipientid,  root_users.usr_screenname recipientscreenname, root_users.usr_firstname recipientfirstname, root_users.usr_email recipientemail  root_strings  left join root_users on root_users.usr_id = root_strings.usr_id  root_strings.parent_id = '1' , root_strings.usr_id not null  ) sq order id desc limit 0,3 

it returns result this,

id     approved recipientid  recipientscreenname   recipientemail        14      1           3          x                   x@yahoo.co.uk 13      n/a        null        y                   y@yahoo.co.uk 13      n/a        null        y                   y@yahoo.co.uk 

then email each of them.

foreach($items_thread $item_thread)  {    $sentmail = mail($item_thread['recipientemail'],$email_subject,$email_content,$email_headers); } 

but logic not correct when closer send y twice of email!

y should 1 email. how can fix - should fix sql query or php code?

the problem null!=null (nor null=null), distinct not consider 2nd , 3rd results same. if change query recipientid shows 0 (e.g coalesce(recipientid,0) rid) problem go away.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -