Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 按用户名获取对话的最后消息_Php_Mysql - Fatal编程技术网

Php 按用户名获取对话的最后消息

Php 按用户名获取对话的最后消息,php,mysql,Php,Mysql,Plis帮助,获取最后消息对话 数据库: id, user_from user_to msg 查询php select * from messages where user_from = 'Michael' AND user_to = 'Daiana' OR user_from = 'Daiana' AND user_to = 'Michael' LEAST(user_to _id, user_from) order by id

Plis帮助,获取最后消息对话

数据库:

id,
user_from
user_to
msg
查询php

select * 
from messages 
where 
      user_from = 'Michael' AND 
      user_to = 'Daiana' OR 
      user_from = 'Daiana' AND 
      user_to = 'Michael' 
LEAST(user_to _id, user_from) 
order by id desc 
limit 1
请帮帮我。例如,他没有列出Daiana和Michael两位用户对话中的最新消息

示例结果:

  • 黛安娜:你好吗
  • 迈克尔:很好,你呢
  • 黛安娜:好的:)

键入样式的聊天室facebook为什么您不能根据desc order中创建的日期获取记录?我认为您应该再增加一列“Createddatetime”。为什么你在这里想要最少的功能?您可以删除最少的函数并增加获取最新记录的限制。是否有任何错误?或者用户名有效并且数据库中有数据吗?为什么不从消息中选择*按id排序描述限制1获取最后一次对话?为什么要反向?此查询没有至少。。。行为您提供最后插入的行。你还要别的东西吗?它坏了。如果我列出5条记录,那么最后一条消息将从第一条开始。你必须列出过去的信息,比如facebook聊天。
select * 
from messages 
where 
  (user_from = 'Michael' AND user_to = 'Daiana') 
  OR 
  (user_from = 'Daiana' AND user_to = 'Michael' )
LEAST(user_to _id, user_from) 
order by id desc 
limit 1