PHP从MySQL数据库中读取单个记录的最佳方法是什么?
SELECT * FROM messages WHERE receiver ='$id' ORDER BY datetime DESC
它显示所有消息,我只希望一个用户发布一个帖子。
答案 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"