douxing1353 2013-03-31 19:32
浏览 42
已采纳

PHP消息表单

I am trying to create a group chat/message system in PHP and HTML. It has been turning out pretty good, but i wanted to change the system to make it more detailed.

I have been trying to make it for that it displays messages made by other users one way, and messages made by you another, kind of like iMessage for the iPhone.

Here is my PHP code...

<div class="groupchat span9" style="height: 200px; overflow: auto;">

<?php

    /*
    * LETS GET THESE MESSAGES PRINTED
    */

    $qry=mysql_query("SELECT * FROM chat ORDER BY chat.id ASC", $con);

    while($row=mysql_fetch_array($qry)) {

        if(!$row['name']) {
            echo '<div class="span5 place-left">';
                echo '<ul class="replies">';
                    echo '<li class="bg-color-orange">';
                        echo '<b class="sticker sticker-left sticker-color-orange"></b>';
                        echo '<div class="avatar"><img src="../content/images/myface.jpg" /></div>';
                        echo '<div class="reply">';
                            echo '<div class="date">'.$row['time'].'</div>';
                            echo '<div class="author">'.$row['name'].'</div>';
                            echo '<div class="text">'.$row['message'].'</div>';
                        echo '</div>';
                    echo '</li>';
                echo '</ul>';
            echo '</div>';
        }

        if($row['name'] == $_SESSION['name']) {
          echo '<div class="span5 place-right">';
                echo '<ul class="replies">';
                    echo '<li class="bg-color-blue">';
                        echo '<b class="sticker sticker-right sticker-color-blue"></b>';
                        echo '<div class="avatar"><img src="../content/images/myface.jpg" /></div>';
                        echo '<div class="reply">';
                            echo '<div class="date">'.$row['time'].'</div>';
                            echo '<div class="author">'.$row['name'].'</div>';
                            echo '<div class="text">'.$row['message'].'</div>';
                        echo '</div>';
                    echo '</li>';
                echo '</ul>';
            echo '</div>';
        }

    }

?>

<a name="groupchatbottom"></a>

</div>

I'm having a problem trying to get it for that it will display messages that arn't made by you. I appreciate any help! Thank you all for your help in advance!

  • 写回答

1条回答 默认 最新

  • douyazi1129 2013-03-31 19:36
    关注

    Just use an if-else statement:

    if($row['name'] == $_SESSION['name']) {
        // post belongs to author
        echo '<div class="author-message">
    
        </div>';  
    }
    else{
        echo '<div class="user-message">
    
        </div>';    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?