donglou1866 2016-03-14 10:26
浏览 18

在php + mysql中重新排列最新的对话

we have building a chat application using php and mysql and our table structure looks like this

converstation_table_name

id
conversation_id
created_at
user_1
user_2

messages

sender
reciever
message
created_at
conversation_id

here are the values in both tables

conversation_table_name

id | con_id(shortname) | created_at | user_1 | user_2 |
 1 | 123132            |   now      |   1    |    5   |
 2 | 123133            |   now      |   1    |    3   |
 3 | 123134            |   now      |   1    |    4   |
 4 | 123135            |   now      |   1    |    2   |     

messages

sender | reciever | message | created_at | conversation_id |
     1 |    3     |   abc   |   now      |     123133      |
     3 |    1     |   cee   |   now      |     123133      |
     1 |    2     |   1411  |   now      |     123135      |
     1 |    5     |   1-5   |   now      |     123132      |

now we want to arrange the output something like this

123132
between 1 - 5
123135
between 1 - 2
123133
between 1 - 3

how to go about it, in short we want to make the latest message in user conversation to appear on top, just like facebook does with it's messaging system, how to go about it, we are still looking for a working answer

  • 写回答

1条回答 默认 最新

  • doujie2356 2016-03-14 10:35
    关注

    Can be introduced new field viewed or seen with datetime field. On visiting message update the field. So can be used order by that field and you will have the viewed time.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器