medj Posted June 6, 2008 Share Posted June 6, 2008 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted June 6, 2008 Share Posted June 6, 2008 SELECT * FROM table ORDER BY age DESC Those over 20 are listed first then those under 20 Quote Link to comment Share on other sites More sharing options...
medj Posted June 6, 2008 Author Share Posted June 6, 2008 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted June 7, 2008 Share Posted June 7, 2008 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.