Jump to content

Results and Anti-Results of Query


medj

Recommended Posts

I was just wondering if there was an optimal way to display the results of a query as well as the anti-results if you know what I mean.

 

	$query = mysql_query( "SELECT * FROM table WHERE `table`.`age` > 20" )

 

So I would first display the results where the age of the person is over 20. But underneath the information, I would like to display the people whose age is under 20.

Is it just a matter of making a $query2 where the age < 20 and display it? Or is there a more better way to do this.

Link to comment
https://forums.phpfreaks.com/topic/109012-results-and-anti-results-of-query/
Share on other sites

Thanks for the reply. I gave that example as I thought there was someway to just show all the values that are not part of your query. This is what my code really looks like:

 

	$function_match = mysql_query( "SELECT components.manufacturer, components.part_num, components.stock FROM components JOIN $bod ON (components.part_num=$bod.manufacturer_num)" )
or die("SELECT Error: ".mysql_error());

$function_no_match = mysql_query( "SELECT components.manufacturer, components.part_num, components.stock FROM components JOIN $bod ON (components.part_num!=$bod.manufacturer_num)" )
or die("SELECT Error: ".mysql_error());

 

The only difference between both of them is that the second one gets all the ones that the first one didn't get.

 

You can actually see what I am trying to do if you go to http://eldoled.blankevolution.com.

Select the radio button match and then click submit. You will see the colored boxes on top which are the matches and then the rest are suppose to be the non matches. For some reason I'm getting a weird result where it seems to be showing each of my non matches 8 times.

For some reason I'm getting a weird result where it seems to be showing each of my non matches 8 times.

It's not weird -- you've corrupted the ON clause.

 

What you want for the second query is this:

 

SELECT components.manufacturer, components.part_num, components.stock FROM components LEFT JOIN $bod ON (components.part_num=$bod.manufacturer_num) WHERE $bod.manufacturer_num IS NULL

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.