Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

mysql - Read the top 10 rows from the database

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 |
+---------+-------------+------+

And I need a PHP script to read the top 10 rows from the database, based on date posted.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...