I have been searching for how to do this but I didn't find anything useful!
So I have the following table with the following columns:
ID | USER | COMMENTS
---------------------
1 | John | 20
2 | Sara | 32
3 | Peter| 10
What I want to do is to pick the user with most comment. I'm using:
<?php
$usermaxresult = mysql_query("SELECT MAX(comments) FROM users");
while ($usermaxrow = mysql_fetch_array($usermaxresult)) {
$max = "MAX(comments)";
echo "$usermaxrow[$max]";
}
?>
But that would only return the number of max comments, not the user with the max comments.
---- WORKED! THANKS FOR THE COMMENTS, CODE (it is in portuguese because I'm portuguese)
$usermaxuploads = mysql_query("SELECT MAX(uploads) as max_count FROM login");
$usermaxuploadsrow = mysql_fetch_array($usermaxuploads);
$maxvar = $usermaxuploadsrow["max_count"];
$usermaxresult = mysql_query("SELECT * from login WHERE uploads = '$maxvar' ");
$usermaxrow = mysql_fetch_array($usermaxresult);
echo $usermaxrow['usuario'];