Forum Moderators: coopster
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
<?
$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
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.