sdat1333 Posted June 28, 2006 Share Posted June 28, 2006 OK, there's a mysql dbOne field will be occupied with integers. I want the system to sort the ten greatest fields in an array or something. Then I need a way to pull the 'id num' (an incremented field) associated with each of the 10 highest integers from that column.Ideas? Sorry if this is a really easy task, I'm new to PHP/MySQLAlso, if theres an easy way to do this using ADOdb that would be preferred (I would like to keep server CPU load down as much as possible, and ADOdb caches previous queries to reduce load.Detailed instructions would be helpful, I'm a HUGE PHP/MySQL noob. :) So please don't assume too much knowledge/ Quote Link to comment https://forums.phpfreaks.com/topic/13161-pulling-the-ten-highest-integers-from-a-mysql-field/ Share on other sites More sharing options...
jworisek Posted June 30, 2006 Share Posted June 30, 2006 is there going to be duplicate values in the column?you can do something like this to get the top ten values:[code]SELECT var FROM table_name ORDER BY var ASC LIMIT 10[/code] and then you can use another query to grab the ID[code]SELECT var_id FROM table_name where var='$var'[/code]You can do this in one query with subselects but I think its easier to understand if you are new by using multiple queries. Quote Link to comment https://forums.phpfreaks.com/topic/13161-pulling-the-ten-highest-integers-from-a-mysql-field/#findComment-51286 Share on other sites More sharing options...
Wildbug Posted June 30, 2006 Share Posted June 30, 2006 Wouldn't this be better?[code]SELECT var_id,var FROM table_name ORDER BY var DESC LIMIT 10[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13161-pulling-the-ten-highest-integers-from-a-mysql-field/#findComment-51368 Share on other sites More sharing options...
jworisek Posted June 30, 2006 Share Posted June 30, 2006 I was working under the assumption that it was 10 highest unique integers and all the IDs for those integers.If its 10 integers and you will get more than 10 IDs, go with my code, otherwise go with wildbugs Quote Link to comment https://forums.phpfreaks.com/topic/13161-pulling-the-ten-highest-integers-from-a-mysql-field/#findComment-51370 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.