如何从数据库中获取并显示最大价值? [英] How to get, and display the biggest values from a database?

查看:88
本文介绍了如何从数据库中获取并显示最大价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何从数据库中获取和显示最大价值吗?我的数据库中有多个值为"gmd"的值,但是如何只显示前三个最大的值呢?在此示例中,我将如何做:

Can anyone tell me how to get and display the biggest values from a database? I have multiple values in my database with the heading "gmd", but how would I get only the first 3 biggest ones to be displayed? How would I do it in this example:

$query  = "SELECT gmd FROM account";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
}

推荐答案

使用查询来排序和限制结果.

Use the query to order and limit the results.

SELECT gmd
FROM account
ORDER BY gmd DESC
LIMIT 3

使用获取数组显示所有结果.

Use your fetch array to display all of the results.

$query  = "SELECT gmd FROM account ORDER BY gmd DESC LIMIT 3";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo $row["gmd"];
}
mysql_free_result($result);

这篇关于如何从数据库中获取并显示最大价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆