计算用户在我的聊天中发送的邮件

时间:2018-12-25 00:39:54

标签: php function chat

首先,我有一个聊天脚本,聊天中的每个用户都有他自己的个人资料和个人资料中的一些信息,例如国家,年龄,磨床,他的照片和他的朋友,我需要以某种方式显示他所有邮件的计数他已经发送了聊天信息,我将在他的个人资料中添加一个新字段,然后输入此号码。

所以在这里,我具有此功能,可以将用户的消息存储在数据库中。

    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);
        }
    }
}

我忘了说函数已经对所有用户的消息进行计数并将其存储在名为“ caction”的my_users表中的列中,但是该函数同时对所有用户的消息进行计数,例如,如果我有0点并且有人发送了聊天中的一条消息,它将为我和他以及所有聊天中的用户计数此消息,但我不想,我想要一个功能来为每个用户计数消息并显示号码。

这是我的桌子:

my_users

user_id
user_name
password
user_photo
user_email
room_id
caction

my_chat

post_id
user_id
post_date
post_message
post_roomid
type
snum
tcolor

在这里,我有我的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;
}
?> 

所以我该如何使每个用户的邮件计数并将其存储在 my_users 表的列中。

1 个答案:

答案 0 :(得分:0)

运行此查询,您将获得每个用户发送的消息数。您可以在他的页面上显示计数,也可以将其存储在某个地方并显示。

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