我一直在寻找如何做到这一点,但我没有发现任何有用的东西!
所以我有下表,其中包含以下列:
ID | USER | COMMENTS
---------------------
1 | John | 20
2 | Sara | 32
3 | Peter| 10
我想做的是选择评论最多的用户。我在用着:
<?php
$usermaxresult = mysql_query("SELECT MAX(comments) FROM users");
while ($usermaxrow = mysql_fetch_array($usermaxresult)) {
$max = "MAX(comments)";
echo "$usermaxrow[$max]";
}
?>
但这只会返回最大评论的数量,而不是拥有最大评论的用户。
---- 工作!感谢您的评论,代码(它是葡萄牙语,因为我是葡萄牙人)
$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'];