Jump to content

Php mysql select highest quotient


jackr1909

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/254256-php-mysql-select-highest-quotient/
Share on other sites

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

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.