简体   繁体   English

使用PHP / MYSQL进行基于对话的消息传递?

[英]Conversation Based Messaging with PHP/MYSQL?

Okay so I'm trying to make it so I can make a conversation based messaging system with one table. 好的,我正在尝试做到这一点,因此我可以使用一个表创建基于会话的消息传递系统。 The user messages a user and we put their id as sent_id and the person who sent it is my_id . 用户向用户发送消息,我们将其ID设置为sent_id ,发送它的人为my_id Now my problem is, it is displaying, but I don't want it to display more than once. 现在我的问题是,它正在显示,但是我不希望它显示多次。 I've been using DISTINCT but that doesn't seem to be working. 我一直在使用DISTINCT但这似乎不起作用。 Example table: 表格示例:

|--ID--|--MY_ID--|--SENT_ID--|
   1        1          2
   2        2          1
   3        1          2

How do I make it only display the latest one? 如何使其仅显示最新的?

(Also $my_id is already escaped, don't worry lol) (另外$my_id已经被转义,不用担心,哈哈)

SELECT `my_id`, `sent_id`, `time_stamp` FROM `messages` WHERE `sent_id`="'.$my_id.'" || `my_id`="'.$my_id.'"

Here is my table: 这是我的桌子:

CREATE TABLE IF NOT EXISTS `messages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `my_id` text NOT NULL,
  `sent_id` text NOT NULL,
  `message` text NOT NULL,
  `file` text NOT NULL,
  `time_stamp` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

Jake, not a 100% sure what you mean about the latest one. 杰克,不是100%肯定您对最新一本书的意思。 Are you talking about ORDER BY DESC? 您是在谈论ORDER BY DESC吗?

SELECT `my_id`, `sent_id`, `time_stamp` 
FROM `messages` 
WHERE `sent_id`="'.$my_id.'" || `my_id`="'.$my_id.'"
ORDER BY id DESC
LIMIT 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM