Jump to content

Check For Duplicate Values in 3 Arrays


aleX_hill

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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'";

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.