Php 私人收件箱中发件人和收件人的背景颜色不同
我用php编写了一个简单的静态私有消息脚本,我希望发送者和接收者的消息具有不同的颜色背景Php 私人收件箱中发件人和收件人的背景颜色不同,php,mysql,css,Php,Mysql,Css,我用php编写了一个简单的静态私有消息脚本,我希望发送者和接收者的消息具有不同的颜色背景 $sql="SELECT message,timestamp from pm WHERE (from_user='".$_SESSION["username"]."' OR from_user='$touser') AND (to_user='$touser' OR to_user='".$_SESSION["username"]."') ORDER BY timestamp";
$sql="SELECT message,timestamp from pm WHERE (from_user='".$_SESSION["username"]."' OR from_user='$touser') AND (to_user='$touser' OR to_user='".$_SESSION["username"]."') ORDER BY timestamp";
$ex=$conn->prepare($sql);
$ex->execute();
while($result=$ex->fetch(PDO::FETCH_ASSOC))
{
echo "<div class='message-view'>";
echo "<p class='subject'>".$result["message"]."</p>";
echo "</div>";
}
$sql=“选择来自pm的消息、时间戳,其中(来自_user='”、$\u会话[“用户名”]。”或来自_user='$touser')和(来自_user='$touser'或to_user='”、$\u会话[“用户名”]。“)按时间戳排序”;
$ex=$conn->prepare($sql);
$ex->execute();
而($result=$ex->fetch(PDO::fetch_ASSOC))
{
回声“;
回显“”$result[“message”]。“
”;
回声“;
}
pm表具有以下属性(id、to_user、from_user、subject、message、timestamp)更改:
$sql="SELECT message,timestamp from pm WHERE (from_user='".$_SESSION["username"]."' OR from_user='$touser') AND (to_user='$touser' OR to_user='".$_SESSION["username"]."') ORDER BY timestamp";
到
然后根据发件人的身份,在特定的课堂上检查:
if ($result['from_user'] == $_SESSION["username"])
echo '<div class="message-view-sender" style="background-color: yellow;">';
else
echo "<div class='message-view'>";
if($result['from\u user']=$\u SESSION[“username”])
回声';
其他的
回声“;
太好了。祝你好运。你有问题吗?你能发布生成的代码吗?是的,添加以下if条件成功了,谢谢!如果($result['from_user']=$_SESSION[“username”])没有问题。请选择它作为正确答案(:
if ($result['from_user'] == $_SESSION["username"])
echo '<div class="message-view-sender" style="background-color: yellow;">';
else
echo "<div class='message-view'>";