更新图片 - 如何在PHP SQL中显示a到b和b的消息?

时间:2017-02-04 16:42:56

标签: php sql database

如何在PHP sql中显示a到b和b的消息?基本上这是我的桌面结构,用于'聊天记录':

ID, Userid, Userid2, Email, Email2, Message, and Date_Posted. 
*Note: Userid and Email is = the received
Note: Userid2 and Email2 is = the sender*

链接类似send.php?userid=1&userid2=2(阅读聊天工作正常)

问题是如何显示每个用户的最后一条消息,例如限制1。

如果用户 A 登录=显示链接发送信息 B

如果用户 B 登录显示链接发送到个人资料 A

更新

Refer Picture

这是我当前用于显示消息的sql仅适用于一方。

<?php
$count=1;
$sel_query="SELECT * from chat_logs where `email` = '$_SESSION[email]' or `email2` = '$_SESSION[email]' ORDER  BY id DESC LIMIT 0,10";
$result = mysql_query($sel_query);
while($row = mysql_fetch_assoc($result)) { ?>
<table width="100%" border="0" bgcolor="white">
  <tr>
    <td width="5%" height="44"></td>
    <td width="9%" valign="top"><img style="width: 40px; height: 40px; border-radius: 100%; background: #eee no-repeat center; background-size: cover;" src="dp/
<?php if ($row["email"]='$_SESSION[email]'){
echo "" . $row["dp1"]. "";
}
else{
echo "" . $row["dp2"]. "";
} ?>">&nbsp;</td>
    <td width="91%" align="left" valign="top"><strong>

<?php if ($row["email"]='$_SESSION[email]'){
echo "" . $row["username"]. "";
}
else{
echo "" . $row["username2"]. "";
} ?>

<a href="sendmessage.php?id=<?php echo $row["userid2"]; ?>&userid2=<?php echo $row["userid"]; ?>"></strong><br><font color="black"><?php echo $row["message1"]; ?></a></a><br><font size="1"><?php echo $row["time1"]; ?></font></td>
  </tr>
</table>
<script type="text/javascript">
</script>
<?php $count++; } ?>

0 个答案:

没有答案