如何显示所有id_following

时间:2016-09-03 14:50:39

标签: php mysql codeigniter model

image

我的代码:

        $this->db->join('followers','followers.id_follower = post.id_account','LEFT');             

        $id_account = $this->session->userdata('id');

        $where = ("followers.id_following=$id_account or post.id_account = $id_account");
        $this->db->where($where);

请帮帮我

1 个答案:

答案 0 :(得分:0)

这样的东西?

在你的控制器中:

    // Set variables
    $page_data = array();
    $id_account = $this->session->userdata('id');

    // Get data
    $this->db->from('post');        
    $this->db->join('followers','followers.id_follower = post.id_account','LEFT');
    $this->db->where('id_following', $id_account);
    $this->db->or_where('id_account', $id_account);
    $page_data['followers'] = $this->db->get();

    // Load views
    $this->load->view('myview', $data);

在你的视野中

    <?php if (!empty($followers)) {
        foreach ($followers as $item) { 
            echo $item['follower_id']; 
        }
    } ?>

你可能想在你的视图中使用简短形式的php,但你明白了。