从数据库中读取前 10 行 [英] Read the top 10 rows from the database
问题描述
我一直在做这个小项目.我有一个看起来像这样的 MySQL 表
I have this small project I have been working on. I have a MySQL table that looks kind of like this
+---------+-------------+------+
| Content | Date Posted | Name |
+---------+-------------+------+
| Content | Date Posted | Name |
+---------+-------------+------+
我需要一个 PHP 脚本来根据发布日期从数据库中读取前 10 行.
And I need a PHP script to read the top 10 rows from the database, based on date posted.
推荐答案
您可以使用 PHPMyAdmin 创建表,或运行这样的脚本:
You can use PHPMyAdmin to create tables, or run a script like this:
CREATE TABLE Contents (
Content MEMO NOT NULL,
DatePosted DATE NOT NULL,
Name VARCHAR2(200) NOT NULL);
然后像这样选择最新的 10 个:
and select the newest 10 like this:
SELECT
t.Content,
t.DatePosted,
t.Name
FROM
Contents t
ORDER BY
DatePosted DESC
LIMIT 10
虽然答案看起来很小,但实际上是一个大问题.你不知道吗?如果您不想每次需要从数据库中获取一些内容时都卡住,也许您应该从阅读一些教程开始.
But while the answer seems small, it is actually a big question. Do you have no idea whatsoever? Maybe you should start by reading some tutorials if you don't want to get stuck every time you need a little something from your database.
这篇关于从数据库中读取前 10 行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!