SELECT * FROM members, newsletter_sent WHERE members.member_flag=1 AND newsletter_sent.newsletter_id !=12 AND newsletter_sent.member_id !=members.member_id
i want member_id's who did not did not receive that particular newsletter.
i am checking this before sending newsletter to member, once it has been sent, i am inserting member_id and newsletter_id into newsletter_sent table.
and your query
SELECT * FROM members, newsletter_sent WHERE members.member_flag=1 AND newsletter_sent.newsletter_id !=12 AND newsletter_sent.member_id !=members.member_id
will defiantly wont give you the required results as in query you are joining the records for the 'newsletter_sent' and 'members' table...
If you want to check whether the member is sent with the current newsletter, then simply check the current 'newsletter_id' and 'member_id' in table 'newsletter_sent', and if no record is found then insert the record else do other stuff..
But, i won't be knowing member_id's. I'll prepare newsletter then submit, it will be entered into database, i'll get that newsletter_id from mysql_insert_id. For sending newsletters to members, i have to check newsletter_sent table with members table. Should i have to write 2 queries?
But, i won't be knowing member_id's. I'll prepare newsletter then submit, it will be entered into database, i'll get that newsletter_id from mysql_insert_id. For sending newsletters to members, i have to check newsletter_sent table with members table. Should i have to write 2 queries?
If you are inserting new newsletter, then definitely none of the members will be sent with the same newsletter, so why dont you directly sent the newsletter directly to all the members that are subscribed for newsletter.
Yes, I can do that. Again, If there are many members and the process stops for some reason, i wont be knowing the members yet to receive newsletters
Then the solution should be to first collect all the members that are sent with the current newsletter_id and get the missing members using the second query. So, collect all the members id here having current newsletter