Welcome Guest, Not a member yet? Register   Sign In
Getting a list of tags
#1

[eluser]eokorie[/eluser]
Hi I hope someone can help. I am trying to get a list of tags for every article posted and I am trying to get these listed underneath each individual post.

This is the SQL that I have in the model:

Code:
public function get_all_entries($limit, $offset, $cat='')
        {
            $this->db->select('*');
            $this->db->select("DATE_FORMAT(gk_blog_posts.date_art,'%W, %D %M %Y') AS article_date", FALSE );
            $this->db->select("Count(gk_blog_comments.id_com) AS TotalComments");
            ($cat)? $this->db->where('idtop_art', $cat) : '' ;
            $this->db->where('status_art','publish');
            // $this->db->where('gk_blog_comments.is_approved','1');
            $this->db->join('gk_users', 'gk_users.id_usr = gk_blog_posts.author_art', 'left');
            $this->db->join('gk_blog_comments', 'gk_blog_comments.idart_com = gk_blog_posts.id_art', 'left');
            $this->db->join('gk_blog_categories', 'gk_blog_categories.id_top = gk_blog_posts.idtop_art', 'left');
            $this->db->order_by('date_art','desc');
            $this->db->group_by('id_art');
            $this->db->limit($limit, $offset);
            $articles = $this->db->get()->result;
            foreach($articles as $article) {
                 $this->db->select('*');  
                 $this->db->from('gk_blog_tags');
                 $this->db->join('gk_blog_posts_tags', 'gk_blog_posts_tags.gk_blog_tag_id = gk_blog_tags.id_tag');
                 $this->db->where('gk_blog_posts_tags.gk_blog_post_id', $article->id_art);
                 $article->tags = $this->db->get()->result;
            }
            return $query->result();
        }


Unfortunately, its just not working. My table structure is show below:

Code:
CREATE TABLE `gk_blog_posts` (
   `id_art` bigint(20) unsigned,
   `author_art` bigint(20),
   `idtop_art` bigint(20),
   `title_art` text,
   `desc_art` text,
   `content_art` longtext,
   `meta_key_art` varchar(255),
   `meta_value_art` longtext,
   `date_art` datetime,
   `date_gmt_art` datetime,
   `status_art` enum('publish','private','static','pending'),
   `modified_art` datetime,
   `modified_gmt_art` datetime,
   `comment_status_art` enum('closed','open','registered only'),
   `name_art` varchar(255),
   `tags_art` varchar(255),
   `read_count_art` bigint(20),
   `tutorial_art` char(1),
   PRIMARY KEY (`id_art`),
   KEY `title_art` (`title_art`,`desc_art`,`content_art`)
) ENGINE=MyISAM DEFAULT CHARSET latin1;


CREATE TABLE `gk_blog_posts_tags` (
   `post_tag_id` int(11),
   `gk_blog_post_id` int(11),
   `gk_blog_tag_id` int(11),
   PRIMARY KEY (`post_tag_id`)
) ENGINE=MyISAM DEFAULT CHARSET latin1;


CREATE TABLE `gk_blog_tags` (
   `id_tag` int(10) unsigned,
   `name_tag` varchar(255),
   `count_tag` bigint(20),
   PRIMARY KEY (`id_tag`)
) ENGINE=MyISAM DEFAULT CHARSET latin1;

Does the SQL I wrote look correct?

Thanks


Messages In This Thread
Getting a list of tags - by El Forum - 08-13-2009, 09:53 AM
Getting a list of tags - by El Forum - 08-13-2009, 10:01 AM
Getting a list of tags - by El Forum - 08-13-2009, 10:13 AM
Getting a list of tags - by El Forum - 08-13-2009, 10:45 AM
Getting a list of tags - by El Forum - 08-13-2009, 11:08 AM
Getting a list of tags - by El Forum - 08-13-2009, 11:20 AM
Getting a list of tags - by El Forum - 08-14-2009, 04:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB