私人收件箱中发件人和收件人的不同背景颜色

时间:2015-03-31 14:43:31

标签: 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";
                        $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>";
                            }

pm表具有以下属性(id,to_user,from_user,subject,message,timestamp)

1 个答案:

答案 0 :(得分:0)

变化:

$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_user  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'>";