【问题标题】:this is a chat box design displaying the sender and receiver messages这是一个显示发送者和接收者消息的聊天框设计
【发布时间】:2013-01-19 18:00:14
【问题描述】:

基本上,此代码有效,但它以相同的颜色显示发送者和接收者 我想要什么?我希望发件人颜色与收件人消息颜色不同

<?php

require_once 'cn.php';

session_start(); // startsession .line17 (username || usernameto='.$username.')

//messages sent or received by the $_SESSION or $_GET["ident"]..line 26


require_once 'protect.php';

$username=$_SESSION['UserID'];

$fiveMinutesAgo = time() - 1000;

$to=$_SESSION['UserTo'];

$sql = 'SELECT

    username, message_content,message_file, message_time,usernameto

        FROM

    messages

        WHERE

    message_time > ' . $fiveMinutesAgo . '

    and ((username='.$username.'

        and usernameto='.$to.') or (usernameto='.$username.'

        and username='.$to.'))

        ORDER BY
    message_time';

    $result = mysql_query($sql, $cn) or

    die(mysql_error($cn));

    //mysql_query ("Update messages set message_file= replace(message_file,' ','');


    while ($row = mysql_fetch_assoc($result)) {

    $hoursAndMinutes = date('g:ia', $row['message_time']);

    $mycontent=$row['message_content'];

    $myfile=$row['message_file'];

    $playfile="<A href=upload/$myfile> $myfile </A>";
/*************************************************************************************************/


    echo '<i><p style="font-family:arial;color:purple;font-size:15px;"><strong>' . $row['username']. '</strong>: <em>(' . $hoursAndMinutes . ')</em> ' . $playfile . $mycontent.'</i></p>';
}


?>

【问题讨论】:

  • 你怎么知道哪个是发送者,哪个是接收者?
  • @ExplosionPills 有趣的是人们如何不积极参与给定的 cmets 和答案......就像他们实际上根本不在乎
  • @roXon 在他们的辩护中,他们可能不像我们那样始终如一地出现在网站上
  • @ExplosionPills 我记得我在这里的第一个问题,我真的很乐意帮助别人帮助我。这对双方都有好处。为了回答者改进答案,对我来说,我真的需要尽快得到准确的答案。

标签: php jquery html mysql css


【解决方案1】:

如果发件人是接收者,您需要知道发件人何时是打开会话的同一个人

【讨论】:

    【解决方案2】:

    假设$username 并且您的列用户名包含用户ID:检查$username 是否与$row['username'] 相同。如果是,则您的消息来自发件人。

    if ($row['username'] == $username)
        $color = 'red';
    else
        $color = 'purple';
    
    echo '<i><p style="font-family:arial;color:'.$color.';font-size:15px;"><strong>' . $row['username']. '</strong>: <em>(' . $hoursAndMinutes . ')</em> ' . $playfile . $mycontent.'</i></p>';
    

    另外:此扩展自 PHP 5.5.0 起已弃用,将来将被删除。相反,应该使用 MySQLi 或 PDO_MySQL 扩展。另请参阅 MySQL:选择 API 指南和相关的常见问题解答以获取更多信息。

    http://www.php.net/manual/en/function.mysql-query.php

    【讨论】:

    • 如果您对我的回答感到满意,请接受(通过单击检查图像)。
    猜你喜欢
    • 2019-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 2017-09-26
    • 1970-01-01
    • 2014-01-12
    • 1970-01-01
    相关资源
    最近更新 更多