Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php AJAX聊天-用户个人提醒(命令)_Php_Oop - Fatal编程技术网

Php AJAX聊天-用户个人提醒(命令)

Php AJAX聊天-用户个人提醒(命令),php,oop,Php,Oop,所以我有一个我一直在编程的ajax聊天, 以及它的命令系统 基本上,如果用户不使用任何命令,我希望系统向用户发出警报,并且只发布斜杠(“/”),并且只有发布斜杠的用户才能查看 但我不知道如何让它起作用。 这是我在聊天室中加载消息的方法: public function loadMessages($username) { $this->fetch = $this->pdo->prepare("SELECT * FROM messages ORDER

所以我有一个我一直在编程的ajax聊天, 以及它的命令系统

基本上,如果用户不使用任何命令,我希望系统向用户发出警报,并且只发布斜杠(“/”),并且只有发布斜杠的用户才能查看

但我不知道如何让它起作用。 这是我在聊天室中加载消息的方法:

    public function loadMessages($username)
    {
        $this->fetch = $this->pdo->prepare("SELECT * FROM messages ORDER BY date, time ASC LIMIT 30");
        $this->fetch->execute();

        while ($row = $this->fetch->fetch(PDO::FETCH_ASSOC))
        {
            if ($row['isAlert'] == '1')
            {
                echo '<b>'.$row['date'].', '.$row['time'].' ['.$row['username'].']: </b><font color="red">'.$row['message'].'</font> <br />';
            }
            else
            {
                echo '<b>'.$row['date'].', '.$row['time'].' ['.$row['username'].']: </b>'.$row['message'].' <br />';
            }
        }
    }
公共函数加载消息($username)
{
$this->fetch=$this->pdo->prepare(“从消息中选择*按日期排序,时间ASC限制30”);
$this->fetch->execute();
而($row=$this->fetch->fetch(PDO::fetch\u ASSOC))
{
如果($row['isAlert']=='1')
{
回显'.$row['date'.','.$row['time'..['.$row['username'.].].]:'.$row['message'.].
; } 其他的 { 回显'.$row['date'.','.$row['time'..['.$row['username'.].].]:'.$row['message'.].
; } } }
您可以在while循环中看到第一个
if语句
,查看消息是否为全局警报,如果是,则将其绘制为红色

但是我如何制作一条只有被提醒的用户才能看到的消息呢?


有什么想法吗?

在页面上隐藏一个
div
,然后使用JavaScript检查命令是否有效,如果没有显示
div

例如:

 <div id="invalidChatCommand" style="display:none">
       <p>
          The command you entered is invalid.
       </p>
 <div>

<script type="text/javascript">
    var chatCommand = document.getElementById("command").value;
    if (chatCommand.length == 1 && chatCommand.substring(0, 1) == "/") { 
       // invalid input detected, show the div
       var invalidCommand = document.getElementById("invalidChatCommand");
       invalidCommand.style.display = "block";
    } else {
       // Send command to the server
    }
</script>


您输入的命令无效。

var chatCommand=document.getElementById(“command”).value; 如果(chatCommand.length==1&&chatCommand.substring(0,1)==“/”{ //检测到无效输入,请显示div var invalidCommand=document.getElementById(“invalidChatCommand”); invalidCommand.style.display=“块”; }否则{ //向服务器发送命令 }
问题是,我需要它显示在聊天室中,并按日期和时间排序。@JonyKale-不要使用新的div,而是附加到现有的div上。您的聊天系统是否有收件人的概念?也就是说,您的数据库模式是否允许专门向给定用户表示消息,或者假设每条消息都发送给每个用户?如果您希望能够进行单播消息传递(无论是从系统、错误消息还是从用户到用户的私人消息传递),您将需要某种方法来指定消息应该发送给谁,并且您的数据模型是执行此操作的最佳位置。(例如,在MySQL数据库的情况下,您可以有一个包含用户名或ID的
recipient
列,或者广播为NULL。)首先,
?真正地其次,这可能应该在客户端完成(即检查输入是否是命令,检查输入是否有效,等等)。不过,这也不能成为您检查服务器的借口。