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
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.