开发者

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

My function within my model is as follows:

    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->ord开发者_如何转开发er_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;


}

I have two further tables -

post_tags : tagID postID tags: tagID name

I have been playing around with joins to try and get it such that along with all my posts etc, the variable returned contains any and all tags that apply to the aforementioned post are passed..

I have tried everything with little to no success.

Could someone please advise? Thanks


You are not using $where correctly.

In this case, $where should be an array of this form:

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

So make sure that $where is an array and not a string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜