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

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.