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
https://forums.phpfreaks.com/topic/195439-check-for-duplicate-values-in-3-arrays/
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

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.