PHP Codeigniter -将posts表连接到TOXI标记数据库存储系统


PHP Codeigniter - Joining a posts table to a TOXI tag database storage system

我在模型中的功能如下:

    function get_all_posts($where='')
{
    $this->load->database();
    $this->db->select('blog.title,blog.permalink,blog.content,blog.author,blog.date,COUNT(comments.ID) as commentcount');
    $this->db->from('blog');
    if($where!=''){
    $this->db->where($where);
    }
    $this->db->order_by("blog.ID", "desc");
    $this->db->join('comments', 'blog.ID = comments.postID','left');
    $this->db->group_by('blog.ID');
    $query=$this->db->get();
    $data=$query->result_array();
    return $data;

}

我还有两个表

post_tags: tagID标签:tagID name

我一直在玩连接,试图得到这样,随着我所有的帖子等,返回的变量包含任何和所有的标签,适用于上述的帖子传递…

我什么都试过了,几乎没有成功。

有人能告诉我吗?由于

你没有正确使用$where。

在本例中,$where应该是如下形式的数组:

$where = array(
    "field_name" => "match_value",
    ....more conditions.......
);

所以要确保$where是一个数组而不是字符串