将结果限制为最后10个 [英] Limit results to last 10

查看:73
本文介绍了将结果限制为最后10个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅显示来自mysql查询的最后10条结果?

How can I display only the LAST 10 results from a mysql query?

我希望在输出结果时忽略最后10个结果之前的任何内容.

I want anything prior to the last 10 results to be ignored when the results are output.

<?php
$query = mysql_query("SELECT * FROM graphs WHERE sid=2 ORDER BY id");
while($info = mysql_fetch_array($query)){
    $graph_id = $info['id'];
    $graph_info = $info['labels'];
    $graph_fig = $info['figures'];

    echo "<label>" . $graph_info .":<span style='background-color: #06F;'>" . $graph_fig . "</span></label>";
}
?>

编辑 我忘了提到结果必须按ID列排序的升序显示.

EDIT I forgot to mention that the results must be displayed in ASCENDING order sorted by the id column.

推荐答案

SELECT * FROM (SELECT * FROM graphs WHERE sid=2 ORDER BY id DESC LIMIT 10) g ORDER BY g.id

正在获取最后10条记录,但结果集仍按升序排列.

Fetching last 10 records but resultset still in asc order.

这篇关于将结果限制为最后10个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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