I am fetching the chat messages between two users and want to display the messages in two different color.
<?php
    session_start();  
?>
<html>
    <head></head>
    <body>
        <?php
            require("config.php");
            $id = $_POST['id'];
            $sql = "select * from users where id='$id'";
            $res = mysqli_query($con, $sql);
            $row = mysqli_fetch_array($res);
            $user_to = $row['name'];
            $sql1 = "select * from chats where user_from='$_SESSION[name]' AND user_to='$user_to' OR user_to='$_SESSION[name]' AND user_from='$user_to' order by id";
            $res1 = mysqli_query($con, $sql1);
            if(mysqli_num_rows($res1) > 0) {
                while($row = mysqli_fetch_array($res1)) {
                    if($row['user_from'] == $_SESSION['name'])
                        $color = 'red';
                    else
                        $color = 'purple';
                    echo '<i><p style="font-family:arial;color:' . $color . ';font-size:15px;">' . $row['msg'] . '</p>';
                }
            } else
                echo "No msgs <br />";
        ?>
    </body>
</html>
for example the user who is logged in , his messages should be in red and whose messages he is checking should be in purple. The trouble is that all the fetched messages is getting red.
 
     
    