Comparing results and only printing NONE duplicates

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
*~mrwizard~*
Forum Newbie
Posts: 1
Joined: Sat Feb 27, 2010 4:55 pm

Comparing results and only printing NONE duplicates

Post 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.
Last edited by Benjamin on Sun Feb 28, 2010 3:26 am, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Comparing results and only printing NONE duplicates

Post by s.dot »

Store the results in two separate arrays and have a look at array_diff() to find the differences between the arrays.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Comparing results and only printing NONE duplicates

Post by Benjamin »

:arrow: Moved to PHP - Code
Post Reply