jackr1909 Posted January 3, 2012 Share Posted January 3, 2012 Hi everyone, i have some mysql data and i want to select the highest, second highest, third highest, etc...... quotient of two records in the same row and echo them, for example, <?php $link = MYLINK; $result = mysql_query("select * from posts WHERE {//this is where it gets tricky// intel/age = highest}"); while($row = mysql_fetch_array($result)){ echo $row['username']; echo "has a value of"; $row['intel']/$row['age']; } echo "<br>"; $result2 = mysql_query("select * from posts WHERE {//this is where it gets tricky// intel/age = second higest}"); while($row = mysql_fetch_array($result2)){ echo $row['username']; echo "has a value of"; $row['intel']/$row['age']; } //This will continue for an indefinite number of times, multiplied by a get value (i've got it under control) ?> Thanks a lot, Jack Quote Link to comment https://forums.phpfreaks.com/topic/254256-php-mysql-select-highest-quotient/ Share on other sites More sharing options...
kickstart Posted January 3, 2012 Share Posted January 3, 2012 Hi Select the calculated value and order by that descending. Then use a limit clause on the select? Not 100% sure that will give you what you want (ie, if you wanted the top 10, if will give you the top ten rows, rather than the rows with the top ten values if those values are duplicated). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/254256-php-mysql-select-highest-quotient/#findComment-1303623 Share on other sites More sharing options...
jackr1909 Posted January 3, 2012 Author Share Posted January 3, 2012 Alright, what i want is the highest row fitting that calculation. I'll work upwards from there, is there any way that i can calculate that in mysql Thanks, Jack Quote Link to comment https://forums.phpfreaks.com/topic/254256-php-mysql-select-highest-quotient/#findComment-1303627 Share on other sites More sharing options...
kickstart Posted January 3, 2012 Share Posted January 3, 2012 Hi Highest is easy:- SELECT *, intel/age FROM posts ORDER BY intel/age DESC LIMIT 1 All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/254256-php-mysql-select-highest-quotient/#findComment-1303648 Share on other sites More sharing options...
jackr1909 Posted January 3, 2012 Author Share Posted January 3, 2012 Thankyou sooo much, Jack Quote Link to comment https://forums.phpfreaks.com/topic/254256-php-mysql-select-highest-quotient/#findComment-1303649 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.