Forum Moderators: coopster

Message Too Old, No Replies

Comparing 2 lists

and retrieving values that only exist in one

         

benihana

1:49 pm on Jun 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi
i have two lists of email addresses that i need to compare.

I need to end up with all the values from list 1 that DONT exist on list 2.

Doing this manually would be too time consuming so am thinking about creating 2 mysql tables and taking each value from table1 to see if it exists in table2, and if not echoing it out screen.

unfortunately i only have limited experience in php. :(

is this a reasonable approach?

any pointers about how to go about it would be great.
thanks

dmorison

2:14 pm on Jun 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PHP / MySQL is one way to do it...

Do you have Excel handy and a bit of VB experience? You could paste list 1 into column A, list 2 into column B, then write a macro to do the same thing, outputting results into column C.

edit_g

2:16 pm on Jun 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You may find this helpful - http:*//msdn.microsoft.com/library/default.asp?url=/library/en-us/dnimo01/html/o2k0601.asp

(hope that link is ok)

flashman

3:32 pm on Jun 18, 2003 (gmt 0)

10+ Year Member



Try compare arrays of emails by this:

<?
$email1=array();
$email2=array();
// if you have lists in mysql database
mysql_connect('','','');
mysql_select_db('mybase');
$res=mysql_query('select * from email1');
while ($res_array=mysql_fetch_array($res))
{
$email1[]=$res_array['email'];
}

$res=mysql_query('select * from email2');
while ($res_array=mysql_fetch_array($res))
{
array_push($email2,$res_array['email']);
}

foreach ($email1 as $e1)
{
$found=false;
foreach ($email2 as $e2)
{
if ($e1==$e2)
{
$found=!$found;
break;
}
}
if (!$found)
echo $e1.'<BR>';
}
?>

i cannot found sql comparing without including selectings:

SELECT email1.email1
FROM email1
WHERE email1.email1 not in (select email1.email1 as e1 from email1,email2 where email1.email1=email2.email2)

so it's not used in PHP but used with Access

brotherhood of LAN

5:09 pm on Jun 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There are also some handy array functions in PHP made for this sort of thing, array_search() being one of them, if you done a foreach on one list and searched through the other it could be done that way.

If it's a bigger list I'd do it the mySQL way. Just as an extra alternative to above - put the emails in list one in into a column, and set it with a UNIQUE key. You'll end up with X amount of emails. When you upload the second list, the duplicates will be ignored, so anything after X would be those in the 2nd list that were NOT in the first.

benihana

7:39 am on Jun 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks everybody - ill give some of the suggestions a try.
:)

benihana

2:00 pm on Jun 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



managed to use the lists as two seperate arrays and used
array_diff to pull out the values req'd.

cheers