Q: 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.
here is my tables:
Table my_users
user_id
user_name
password
user_photo
user_email
room_id
caction

Table my_chat
post_id
user_id
post_date
post_message
post_roomid
type
snum
tcolor

and here i have my 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.

A: 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>

