如何一个用户只获取一条消息

时间:2014-02-15 09:29:04

标签: php mysql

PHP从MySQL数据库中读取单个记录的最佳方法是什么?

SELECT * FROM messages WHERE receiver ='$id' ORDER BY datetime DESC

它显示所有消息,我只希望一个用户发布一个帖子。

3 个答案:

答案 0 :(得分:1)

使用LIMIT

"SELECT * FROM messages WHERE receiver ='$id' ORDER BY datetime DESC LIMIT 1" 

答案 1 :(得分:1)

Limit会这样做。您可以使用

"SELECT * FROM messages WHERE receiver ='$id' ORDER BY datetime DESC LIMIT 1" 

或者你可以喜欢

"SELECT * FROM messages WHERE receiver ='$id' ORDER BY datetime DESC LIMIT 0,1" 

答案 2 :(得分:0)

在查询中使用LIMIT:

"SELECT * FROM messages WHERE receiver ='$id' ORDER BY datetime DESC LIMIT 1"