简体   繁体   English

计算我的聊天中用户发送的消息

[英]count messages that sent by users in my chat

first i have a chat script and every user in my chat have his own profile and some information inside his profile like, country, age, grinder, his photo and his friends, somehow i need to display the count of his all messages that he had sent in chat, and i'll make a new field in his profile ti put this number. 首先,我有一个聊天脚本,聊天中的每个用户都有他自己的个人资料以及个人资料中的一些信息,例如国家,年龄,磨床,他的照片和他的朋友,我需要以某种方式显示他拥有的所有消息的计数发送聊天信息,然后我将在他的个人资料中添加一个新字段,然后输入此号码。

so here i have this function that store messages for users in database. 所以这里我有这个功能,可以在数据库中为用户存储消息。

    function userPostChat($content, $snum = ''){
    global $mysqli, $data;
    $lact = calMinutes(3);
    $style = escape($data['bccolor'] . ' ' . $data['bcbold']);
    $mysqli->query("INSERT INTO `my_chat` (post_date, user_id, post_message, post_roomid, type, snum, tcolor) VALUES ('" . time() . "', '{$data['user_id']}', '$content', '{$data['user_roomid']}', 'public', '$snum', '$style')");
    $last_id = $mysqli->insert_id;
    $mysqli->query("UPDATE my_users SET caction = caction + 1 WHERE user_roomid = '{$data['user_roomid']}' and last_action > '$lact'");
    if($snum != ''){
        $user_post = array(
            'post_id'=> $last_id,
            'type'=> 'public',
            'post_date'=> time(),
            'tcolor'=> $style,
            'post_message'=> $content,
        );
        $post = array_merge($data, $user_post);
        if(!empty($post)){
            return createLog($data, $post);
        }
    }
}

i forget to say that function already count messages from all users and store it in column inside my_users table called ' caction ' but this function count the messages for all users in the same time like, if i have 0 points and someone sent a message in chat it will count this message for me and him and all users in chat, and i don't wanna it, i want a function to count messages for every user and display the number. 我忘了说该功能已经对所有用户的消息进行计数并将其存储在名为“ caction”的my_users表中的列中,但是该函数同时对所有用户的消息进行计数,例如,如果我有0分并且有人在其中发送了一条消息聊天时,它将为我和他以及所有聊天的用户计算此消息,但我不想,我想要一个功能为每个用户计算消息并显示数字。

here is my tables: 这是我的桌子:

Table my_users my_users

user_id
user_name
password
user_photo
user_email
room_id
caction

Table my_chat my_chat

post_id
user_id
post_date
post_message
post_roomid
type
snum
tcolor

and here i have my chat_file.php 在这里,我有我的chat_file.php

function userPostChatFile($content, $file_name, $type, $file_name2 = ''){
    global $mysqli, $data;
    $lact = calMinutes(3);
    $mysqli->query("INSERT INTO `my_chat` (post_date, user_id, post_message, post_roomid, type, file) VALUES ('" . time() . "', '{$data['user_id']}', '$content', '{$data['user_roomid']}', 'public', '1')");
    $rel = $mysqli->insert_id;
    $mysqli->query("UPDATE my_users SET caction = caction + 1 WHERE user_roomid = '{$data['user_roomid']}' and last_action > '$lact'");
    if($file_name2 != ''){
        $mysqli->query("INSERT INTO `my_upload` (file_name, date_sent, file_user, file_zone, file_type, relative_post) VALUES
        ('$file_name', '" . time() . "', '{$data['user_id']}', 'chat', '$type', '$rel'),
        ('$file_name2', '" . time() . "', '{$data['user_id']}', 'chat', '$type', '$rel')
        ");
    }
    else {
        $mysqli->query("INSERT INTO `my_upload` (file_name, date_sent, file_user, file_zone, file_type, relative_post) VALUES ('$file_name', '" . time() . "', '{$data['user_id']}', 'chat', '$type', '$rel')");
    }
    return true;
}

if(!myAllow($data['allow_image']) || muted() || roomMuted()){ 
    die();
}
if (isset($_FILES["file"])){
    ini_set('memory_limit','128M');
    $info = pathinfo($_FILES["file"]["name"]);
    $extension = $info['extension'];
    $origin = escape(filterOrigin($info['filename']) . '.' . $extension);
    if ( fileError() ){
        echo 1;
        die();
    }
    if (isImage($extension)){
        $imginfo = getimagesize($_FILES["file"]["tmp_name"]);
        if ($imginfo !== false) {

            $width = $imginfo[0];
            $height = $imginfo[1];
            $type = $imginfo['mime'];

            $fname = encodeFileTumb($extension);
            $file_name = $fname['full'];
            $file_tumb = $fname['tumb'];

            move_uploaded_file(preg_replace('/\s+/', '', $_FILES["file"]["tmp_name"]), "../upload/chat/" . $file_name);

            $source = '../upload/chat/' . $file_name;
            $tumb = '../upload/chat/' . $file_tumb;
            $img_path = $data['domain'] . "/upload/chat/" . $file_name;
            $tumb_path = $data['domain'] . "/upload/chat/" . $file_tumb;

            $create = imageTumb($source, $tumb, $type, 180);
            if(file_exists($source) && file_exists($tumb)){
                $check_tumb = getimagesize($tumb);
                if ($check_tumb !== false) {
                    $myimage = tumbLinking($img_path, $tumb_path);
                    userPostChatFile($myimage, $file_name, 'image', $file_tumb);
                }
                else {
                    $myimage = linking($img_path);
                    userPostChatFile($myimage, $file_name, 'image');
                }
            }
            else {
                $myimage = linking($img_path);
                userPostChatFile($myimage, $file_name, 'image');
            }
            echo 5;
            die();


        }
        else {
            echo 1;
            die();
        }
    }
    else if (isFile($extension)){
        $file_name = encodeFile($extension);
        move_uploaded_file(preg_replace('/\s+/', '', $_FILES["file"]["tmp_name"]), "../upload/chat/" . $file_name);
        $myfile = $data['domain'] . "/upload/chat/" . $file_name;
        $myfile =  fileProcess($myfile, $origin);
        userPostChatFile($myfile, $file_name, 'file');
        echo 5;
        die();
    }
    else if (isMusic($extension)){
        $file_name = encodeFile($extension);
        move_uploaded_file(preg_replace('/\s+/', '', $_FILES["file"]["tmp_name"]), "../upload/chat/" . $file_name);
        $myfile = $data['domain'] . "/upload/chat/" . $file_name;
        $myfile =  musicProcess($myfile, $origin);
        userPostChatFile($myfile, $file_name, 'music');
        echo 5;
        die();
    }
    else {
        echo 1;
    }
}
else {
    echo 1;
}
?> 

so how i can make a function to count messages for each user and store it in column in my_users table. 所以我如何使一个函数为每个用户计数消息并将其存储在my_users表的列中。

Run this query you will get the number of messages send by each user. 运行此查询,您将获得每个用户发送的消息数。 You can either display the count on his page or store it somewhere and display it. 您可以在他的页面上显示计数,也可以将其存储在某个地方并显示。

SELECT COUNT(*) AS no_messages FROM my_chat WHERE user_id = <user id here>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我有一个带有 PHP 和 Ajax 的聊天应用程序。我想使用 php 查询根据发送或接收的消息显示用户 - I have a chat application with PHP and Ajax. I want to display users according to sent or received messages using php query 从聊天消息列表中删除被阻止的用户 - Remove blocked users from chat messages list Mysql查询:如何获取向状态为= 1的特定用户发送消息的用户数? - Mysql query: How can I get the number of the users who sent messages to my specific user with status =1? 根据发送时间使用 AJAX 脚本检索聊天消息 - Retrieving chat messages with AJAX script based on time they were sent 传递消息时出错我自己的PHP聊天室 - Error delivering messages My own PHP Chat 如何在php mysqli中计算多个用户的消息 - how to count multiple users messages in php mysqli 在php mysqli中计算两个用户的消息 - count messages two users in php mysqli 可以计算PHP中通过SMTP发送的邮件数量吗? - Possible to count number of messages sent via SMTP in PHP? 防止聊天消息从 MySQL 服务器发送后在浏览器中执行脚本? - Prevent chat messages from executing scripts in the browser after being sent from MySQL server? 重新排序聊天选项卡,使包含最新接收或发送消息的选项卡位于列表顶部 - Reorder chat tabs so tabs with newest received or sent messages are on top of list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM