Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.16 KB | None | 0 0
  1. $this->db->select("*, articles.article_id as tmp_art_id,
  2.         (SELECT COUNT(".$this->db->dbprefix."comments.comment_id)
  3.             FROM ".$this->db->dbprefix."comments WHERE ".$this->db->dbprefix."comments.comment_parent_id = ".$this->db->dbprefix."articles.article_id
  4.                 AND ".$this->db->dbprefix('comments.comment_on_module')." = '".$this->router->fetch_module()."')
  5.         AS article_num_comment,
  6.         (SELECT GROUP_CONCAT(".$this->db->dbprefix."category.category_id) FROM ".$this->db->dbprefix."category
  7.             JOIN ".$this->db->dbprefix."cat2article ON ".$this->db->dbprefix."cat2article.cat2_category_id = ".$this->db->dbprefix."category.category_id
  8.             JOIN ".$this->db->dbprefix."articles ON ".$this->db->dbprefix."articles.article_id = ".$this->db->dbprefix."cat2article.cat2_article_id
  9.             WHERE ".$this->db->dbprefix."articles.article_id = tmp_art_id)
  10.         AS cat_id,
  11.         (SELECT GROUP_CONCAT(".$this->db->dbprefix."category.category_title) FROM ".$this->db->dbprefix."category
  12.             JOIN ".$this->db->dbprefix."cat2article ON ".$this->db->dbprefix."cat2article.cat2_category_id = ".$this->db->dbprefix."category.category_id
  13.             JOIN ".$this->db->dbprefix."articles ON ".$this->db->dbprefix."articles.article_id = ".$this->db->dbprefix."cat2article.cat2_article_id
  14.             WHERE ".$this->db->dbprefix."articles.article_id = tmp_art_id)
  15.         AS cat_title,
  16.         (SELECT GROUP_CONCAT(".$this->db->dbprefix."category.category_url) FROM ".$this->db->dbprefix."category
  17.             JOIN ".$this->db->dbprefix."cat2article ON ".$this->db->dbprefix."cat2article.cat2_category_id = ".$this->db->dbprefix."category.category_id
  18.             JOIN ".$this->db->dbprefix."articles ON ".$this->db->dbprefix."articles.article_id = ".$this->db->dbprefix."cat2article.cat2_article_id
  19.             WHERE ".$this->db->dbprefix."articles.article_id = tmp_art_id)
  20.         AS cat_url", FALSE);
  21.  
  22.         $this->db->join('cat2article', 'cat2article.cat2_article_id = articles.article_id');
  23.         $this->db->join('category', 'category.category_id = cat2article.cat2_category_id');
  24.         $this->db->groupby('articles.article_id');
  25.  
  26.         if ($this->article_type) $this->db->where('article_type',$this->article_type);
  27.         if ($this->article_url) $this->db->where('article_url',$this->article_url);
  28.         if ($this->article_publish) $this->db->where('article_publish',$this->article_publish);
  29.         if (isset($this->current_page) and $this->per_page) $this->db->limit($this->per_page, $this->current_page);
  30.         if ($this->category_url) $this->db->where('category_url',$this->category_url);
  31.  
  32.         $this->db->order_by('article_datetime','desc');
  33.  
  34.         $article = $this->db->get('articles')->result_array();
  35.        
  36.         if (array_key_exists('0', $article))
  37.         {
  38.             foreach (array_keys($article) AS $post_key)
  39.             {
  40.                 $tmp_categories = explode(',', $article[$post_key]['cat_title']);
  41.                 $tmp_url_categories = explode(',', $article[$post_key]['cat_url']);
  42.                 $article[$post_key]['category'] = '';
  43.                 foreach (array_keys($tmp_categories) AS $key)
  44.                 {
  45.                     $tmp_categories[$key] = anchor('category/read/' . $tmp_url_categories[$key], $tmp_categories[$key]);
  46.                 }
  47.                 $article[$post_key]['category'] = implode(', ', $tmp_categories);
  48.             }
  49.         }
  50.         $this->count_rows = count($article);//printvar($article);die;
  51.         return $article;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement