aleX_hill Posted March 16, 2010 Share Posted March 16, 2010 OK, here is the situation. I have a mailing list with the following basic structure: id - int name - varchar email - varchar list1 - bool list2 - bool list3 - bool Now when the user sends an email to the group they get a checkbox for list1, list2 and list3. I want to send an email to anyone who has true in the corresponding list. The best way that I can see this is by doing something like this: $myarray = array(); if($_POST['list1']) { $result = mysql_query("SELECT * FROM mailinglist WHERE list1='true'); while($row = mysql_fetch_assoc($result)) { $myarray[] = $row['email']; } } //REPEAT FOR list2 and list3 Then I should have an array with all the email addresses in it, but if people subscribe to two of the selected lists, they will be duplicates in the list. How can I ensure that no duplicates occur? Quote Link to comment Share on other sites More sharing options...
aeroswat Posted March 16, 2010 Share Posted March 16, 2010 $result = mysql_query("SELECT * FROM mailinglist WHERE list1='true' OR list2='true' OR list3='true'"); you mean that? Quote Link to comment Share on other sites More sharing options...
aleX_hill Posted March 16, 2010 Author Share Posted March 16, 2010 I tried something similar to that with the list1='true' being similar to list1='$_POST[list1]' but I was getting users which had not subscribed to either of the selected lists. I will play around with the syntax and see what I can get. I think the error occurred when $_POST['list1'] was not selected and it matched users with list1='false' . Cheers, Alex Quote Link to comment Share on other sites More sharing options...
aleX_hill Posted March 17, 2010 Author Share Posted March 17, 2010 OK, I found a solution which works: $query = "SELECT * FROM mailinglist WHERE id = 'false'"; //the id=false just allows me to use the OR at the beginning of all statements below if($_POST['list1']) $query .= " OR list1='true'"; if($_POST['list2']) $query .= " OR list2='true'"; if($_POST['list3']) $query .= " OR list3='true'"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.