【问题标题】:How to display all the id_following如何显示所有 id_following
【发布时间】:2017-01-11 12:04:13
【问题描述】:

我的代码:

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

请帮帮我

【问题讨论】:

  • 这段代码会发生什么?你提取并循环提取了吗?
  • 你需要使用 $this->db->select 和 $this->db->get()
  • 如何获取id_following
  • 如何获取id_following在哪里?
  • 以上代码只显示基于id_following的会话不全面:$where = ("followers.id_following=$id_account or post.id_account = $id_account");

标签: php mysql codeigniter model


【解决方案1】:

这样的?

在你的控制器中:

    // 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,但您明白了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-22
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-28
    • 2017-07-11
    相关资源
    最近更新 更多