php
  • mysql
  • css
  • 2015-03-31 211 views 1 likes 
    1

    我在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>"; 
              } 
    

    的分表具有以下屬性(ID ,to_user,FROM_USER,主題,消息,時間戳)

    +1

    這很好。祝你好運。你有問題嗎? – 2015-03-31 14:44:36

    +0

    你可以發佈生成的代碼嗎? – Ted 2015-03-31 14:44:39

    +0

    http://postimg.org/image/otycffqsn/ – user3783952 2015-03-31 14:54:34

    回答

    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'>"; 
    
    +0

    是的,如果條件成功,添加以下內容,謝謝! if($ result ['from_user'] == $ _ SESSION [「username」]) – user3783952 2015-03-31 15:02:27

    +0

    沒問題。只是請選擇它作爲正確的答案(: – 2015-04-01 08:36:33

    相關問題