doujiena0025 2013-05-16 22:28
浏览 12

使用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. 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. 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)

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 ;
  • 写回答

1条回答 默认 最新

  • doupo6967 2013-05-16 22:44
    关注

    Jake, not a 100% sure what you mean about the latest one. Are you talking about 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
    
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答