Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.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 根据codignitor中另一个mysql表的post_id匹配获取会话用户_id结果_Php_Mysql_Codeigniter - Fatal编程技术网

Php 根据codignitor中另一个mysql表的post_id匹配获取会话用户_id结果

Php 根据codignitor中另一个mysql表的post_id匹配获取会话用户_id结果,php,mysql,codeigniter,Php,Mysql,Codeigniter,我创建了一个函数来计算基于下面2个db表的帖子总数 1-员额: post_id user_id =========== ==== 61 122 62 122 96 122 97 122 98 122 2-后置元: meta_id post_id status ======== ======= ====== 1 61 1

我创建了一个函数来计算基于下面2个db表的帖子总数

1-员额:

    post_id user_id 
=========== ==== 
          61 122
          62 122
          96 122
          97 122
          98 122
2-后置元:

   meta_id  post_id   status 
   ======== =======   ======
       1      61         1
       2      62         0
       3      62         1
       4      91         1
       5      97         1
       6      98         1
由于用户id存在于posts表中,而两个表上的唯一标识符都是post\u id,因此我希望统计所有状态为1且用户id为$user\u id的post 这是迄今为止我的模型函数

/**
 * The function get_all_user_post_count gets all count posts for admin dashboard
 * 
 * @return array with posts or false 
 */
public function get_all_user_post_count($user_id) {
    $this->db->select('network_name,COUNT(meta_id) as number', false);
    $this->db->from('posts_meta');
    $this->db->join('posts', 'posts_meta.post_id=posts.post_id', 'left');
    $this->db->where(['status' => '1', 'user_id' => $user_id]);
    $this->db->group_by('network_name');
    $this->db->order_by('network_name');
    $query = $this->db->get();
    if ($query->num_rows() > 0) {
        $result = $query->result();
        // Create new array
        $new_array = [];
        foreach ($result as $data) {
            $new_array[$data->network_name] = $data->number;
        }
        return $new_array;
    } else {
        return false;
    }
}
这是迄今为止我的控制器功能

// Count all sent posts per social network
        $count_sent_posts = $this->posts->get_all_user_post_count($this->user_id);
        $this->footer = [
            'statistics' => $statistics,
            'sent' => $count_sent_posts
        ];
        $this->user_layout();
发生数据库错误,错误号:1052

where子句中的“status”列不明确

posts\u meta
左侧选择网络名称、计数(meta\u id)作为数字 加入
posts
上的
posts\u meta
post\u id
=
posts
post\u id
其中
状态
='1'和
用户id
='118'分组依据
网络名称
订购依据
网络名称

文件名:models/Posts.php

电话号码:393

试试这个=>

public function get_all_user_post_count($user_id) {
    $where = array('posts_meta.status ' => 1 , 'posts.user_id ' => $user_id);
    $this->db->select('posts_meta.network_name,COUNT(posts_meta.meta_id) as number', false);
    $this->db->from('posts_meta');
    $this->db->join('posts', 'posts_meta.post_id=posts.post_id', 'left');
    $this->db->where($where);
    $this->db->group_by('posts_meta.network_name');
    $this->db->order_by('posts_meta.network_name');
    $query = $this->db->get();
    if ($query->num_rows() > 0) {
        $result = $query->result();
        // Create new array
        $new_array = [];
        foreach ($result as $data) {
            $new_array[$data->network_name] = $data->number;
        }
        return $new_array;
    } else {
        return false;
    }
}