简体   繁体   English

Cometchat,按发送日期顺序排序

[英]Cometchat, order by sent date desc

Good day, 美好的一天,

I'm looking to order my cometchat chats by last sent date (For example: 1 day ago, 3 days ago, 8 days ago, etc..) for a private messaging system i am working to integrate. 我希望在最后发送日期(例如:1天前,3天前,8天前等)之前订购我的cometchat聊天记录,以进行我正在集成的私人消息传递系统。

However every time i run the command: 但是每次我运行命令:

(select distinct(f.member_id) id, f.display_name username from    
cometchat m1, members f where (f.member_id = m1.from and m1.to = '1') 
or (f.member_id = m1.to and m1.from = '1')) order by sent desc 

Which is taken from the official cometchat admin panel, i am correctly displayed the information in question (however it's unorganized. It organizes itself by last member id from the members table. instead of that from cometchat.) This is the example: http://i.imgur.com/ZfqAerr.png 这是从官方cometchat管理面板上获取的,我正确地显示了有问题的信息(但是它是无组织的。它是根据members表中的最后一个成员ID进行组织的。而不是来自cometchat。)例如: http:/ /i.imgur.com/ZfqAerr.png

Now, if i use the following command: 现在,如果我使用以下命令:

(select distinct(f.member_id) id,sent, f.display_name username from    
cometchat m1, members f where (f.member_id = m1.from and m1.to = '1') 
or (f.member_id = m1.to and m1.from = '1')) order by sent desc 

It does output the "sent" times from cometchat, but it also ungroups all the messages sent (so it's like page by page, instead of group messaging.) Proof: http://i.imgur.com/dtJegw0.png 它确实输出来自cometchat的“已发送”时间,但同时也取消了所有已发送消息的分组(因此就像逐页发送,而不是组消息传递。)证明: http : //i.imgur.com/dtJegw0.png

So what steps must i take in order to make it so it displays both tables accurately in a grouped format by last sent time? 那么我必须采取什么步骤才能使其在上次发送时间之前以分组格式准确显示两个表?

This is the Cometchat table structure: i.imgur.com/s2Nf8xd.png 这是Cometchat表的结构:i.imgur.com/s2Nf8xd.png

This is the members table structure: i.imgur.com/mcq2Pyp.png 这是成员表的结构:i.imgur.com/mcq2Pyp.png

Here is SQL that we would suggest to address this issue: 这是我们建议解决此问题的SQL:

select 
  distinct(f.member_id) id, 
  f.display_name username, 
  max(sent) senttime 
from cometchat m1, members f 
where (f.member_id = m1.from and m1.to = '1') 
   or (f.member_id = m1.to and m1.from = '1') 
group by f.member_id 
order by sent desc

The group_by keeps messages sent from or to a particular member together. group_by使从特定成员发送或到特定成员的消息保持在一起。

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

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