Page 1 of 1

Comparing results and only printing NONE duplicates

Posted: Sat Feb 27, 2010 5:00 pm
by *~mrwizard~*
I know this may seem trival, but I have been stuck trying to figure this out.

I have two mysql result queries that I am trying to compare to each other and then only display the ones that do not match each other.

Code: Select all

$result202 = mysql_query("SELECT * FROM (SELECT * FROM scheduledjobs WHERE propid='$propid201' AND departclean='ON' AND date<'$workdate' ORDER BY date DESC) AS foo GROUP BY propid");
 
while ($row202 = mysql_fetch_array($result202))
{
$propid202 = $row202['propid'];
$lastdate202 = $row202['date'];
 
if($lastdate202<=$lastdepart){
/*echo "$propid202 - These are just departures with a last date of $lastdate202<br>";*/
 
$result203 = mysql_query("SELECT * FROM (SELECT * FROM scheduledjobs WHERE propid='$propid202' AND arrivalchk='ON' AND date BETWEEN '$lastdepart' AND '$workdate' ORDER BY date DESC) AS foo GROUP BY propid");
 
while ($row203 = mysql_fetch_array($result203))
{
$propid203 = $row203['propid'];
$lastdate203 = $row203['date'];
echo "$propid202 - These are the departures with arrivals within $lastdepart and $workdate<br>";
}
That is the code thus far and each query gives me the result that I am looking for. I am trying to compare the $propid202 and $propid203 to one another and only print the $propid202 results that do not match the $propid203 results.

Any help would be much appreciated.

Re: Comparing results and only printing NONE duplicates

Posted: Sat Feb 27, 2010 11:02 pm
by s.dot
Store the results in two separate arrays and have a look at array_diff() to find the differences between the arrays.

Re: Comparing results and only printing NONE duplicates

Posted: Sun Feb 28, 2010 3:27 am
by Benjamin
:arrow: Moved to PHP - Code