MySQL选择第二行 [英] Mysql Select Second Row

查看:103
本文介绍了MySQL选择第二行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mysql问题.

I have a mysql question.

我的网站上有一个新闻版块,我想显示两个最新项目. 如果我这样做:

I have a news section on my website, and I want to display the two latest items. If I do:

SELECT * FROM nieuws ORDER BY id DESC LIMIT 1

它选择最新的项目, 现在我要选择倒数第二项.

it selects the latest item, and now I want to select the second to last item.

你们知道怎么做吗?

///编辑

现在它不起作用了,这是我的代码:(我已经包括连接了;))

Now it doesn't work, here's my code: (I have connect included ;) )

            $select = mysql_query("SELECT * FROM nieuws ORDER BY id DESC LIMIT 1");
            while($row = mysql_fetch_assoc($select)) {
            $datum = $row['time'];
            $titel = $row['title'];
            $bericht = $row['message'];
            ?>
            <div class="entry">

                <span class="blue date"><?php echo "$datum"; ?></span>
                <h3><?php echo "$titel"; ?></h3>
                <p><?php echo "$bericht"; ?></p> <br />
            </div><!-- end of entry --> <?php } ?>
            <?php 
            $select2 = mysql_query("SELECT * FROM nieuws ORDER BY id DESC LIMI 1, 1");
            while($row2 = mysql_fetch_assoc($select2)) {
                $datum = $row2['time'];
                $titel = $row2['title'];
                $bericht = $row2['message'];
                ?>
            <div class="entry">
                <span class="green date"><?php echo "$datum"; ?> </span>
                <h3><?php echo "$titel"; ?></h3>
                <p><?php echo "$bericht"; ?></p>
            </div> <!-- end of entry --> <?php } ?>
        </div><!-- end of news --> 

推荐答案

SELECT * FROM nieuws ORDER BY id DESC LIMIT 2-选择最后2个项目

SELECT * FROM nieuws ORDER BY id DESC LIMIT 1, 1-仅选择第二项

这篇关于MySQL选择第二行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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