Jump to content

Check duplicate numbers from two tables


cow

Recommended Posts

Hello to all,

 

I have two database tables, which in the first row both contain numbers. I want to use php to find out which numbers from the 2nd table (let's name it k34) is found in the first (that one we will name report) and which numbers are not found in there.

 

Can some one give me any clues?

 

Thank you in advanced.

Link to comment
https://forums.phpfreaks.com/topic/125428-check-duplicate-numbers-from-two-tables/
Share on other sites

$k34q = mysql_query("SELECT * FROM k34");

$i = 0;
while($Look = mysql_fetch_array($k43q))
{
$k43[$i] = $Look['ColumnName'];
$i ++;
}

$Reportq = mysql_query("SELECT * FROM Report");

$i = 0;
while($Look = mysql_fetch_array($Reportq))
{
$Report[$i] = $Look['ColumnName'];
$i ++;
}

$e = 0;
$j = 0;

foreach ($k34 as $v)
{
$i = 0;
foreach($Report as $k)
	{
	if($k == $v)
		{
		$i = 1;
		}
	}

if($i == 1)
	{
	$Found[$e] = $v;
	$e ++;
	}
else
	{
	$Lost[$j] = $v;
	$j ++;
	}
}
echo "Found:<br>";
foreach ($Found as $v)
{
echo $v . "<br>";
}

echo "<br><br>Lost:<br>";
foreach ($Lost as $v)
{
echo $v . "<br>";
}

 

Simple, long and unoptimized, but it will do

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.