gpt4 book ai didi

php - 消息传递 对话 php

转载 作者:行者123 更新时间:2023-11-29 21:57:05 31 4
gpt4 key购买 nike

我已经创建了消息系统,在 messages.php 上我想显示消息对话,应该显示最后一条消息,但不知道查询,因为我是 php 新手,这里是数据库信息

  table:conversation_chat            table2:chat
conversation_id: primary unique id: primary unique
from: conversation_id:
to: from_user:
time: to_user:
message:
subject:

请有人能帮助我

 <?php

$req3 = mysql_query("SELECT * FROM `conversation_chat` WHERE
`user_to`='$userid1'");
$hy= mysql_fetch_array($req3);

$convo = $hy['conversation_id'];

if(mysql_num_rows($req3)!=0){

$req4 = mysql_query("SELECT * FROM `chat` WHERE `to`='$userid1' AND

`conversation_id`='$convo'");
while($dn1 = mysql_fetch_array($req4))
{
?>

<td><img alt="example image" src="avatar.png"> &nbsp; &nbsp; <a
href="read?id=<?php echo $dn1['id']; ?>"><?php echo
htmlentities($dn1['from'], ENT_QUOTES, 'UTF-8'); ?></a></td>



<td><span class="label vd_bg-green append-icon">

<?php
echo $dn1['subject']; ?></span></td>
<td style="width:80px" class="text-right">

<strong><?php echo timeAgo($dn1['time']); ?></strong></td><td

style="width:80px" class="text-right">
<?php echo '<a
href="mdelete.php?id='. $dn1['id'] .'">Delete</a>'; ?></td>
</tr>
<?php
}}else{ echo "No new messages";}
?>

最佳答案

好的,您刚刚编辑了数据库信息。现在我了解了您的数据库是怎样的。

您必须在chat2中添加一个DATETIME类型的“时间”列

SELECT * 

FROM `chat`

WHERE `to`='$userid1'

AND

`conversation_id`='$convo'

ORDER BY time DESC //Change the order from last to older

如果您只想要最后一条消息,并且它是 MySQL 数据库,您可以添加

LIMIT 1

关于php - 消息传递 对话 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33037195/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com