请告诉我,如何显示上一次接收或发送的消息的对话框列表?

我尝试过这种方式,但这不是正确的解决方案:
$viewLastMsg = R::findAll('chats', 'ORDER BY id DESC LIMIT 1');
foreach ($viewLastMsg as $vLM)
{
if(
($vLM->sender_type == 'user' && $vLM->sender_id == $_SESSION['logged_user']->id && $vLM->recipient_id == $bot->id)
||
($vLM->sender_type == 'bot' && $vLM->sender_id == $bot->id && $vLM->recipient_id == $_SESSION['logged_user']->id)
)
{
echo $vLM->message;
}
}也许使用SQL查询?
发布于 2020-04-22 21:01:11
如下所示:
$viewLastMsg = R::findAll('chats',
WHERE (sender_type=bot,...)
OR (sender_type = user,...) ',
'ORDER BY id DESC');
foreach($viewLastMsg as $last):
echo $last->message;
endforeach;发布于 2020-04-22 20:42:06
您可以使用类似于下面的内容
SELECT * FROM
(SELECT * from your_table order by id
,send_time desc)
LIMIT 1https://stackoverflow.com/questions/61365207
复制相似问题