<?php

 class Noticia_model extends CI_Model{

     public function get_news_by_id($id = 0) {
        
        if($id == 0) {
            return $this->get_all_news();
        } else {
            $this->db->select('n.*')
                ->from('news AS n')
                ->where('n.id', $id);
         
            return $this->db->get();
        }
        
     }
     
     public function get_all_noticias($per_page, $offset) {
        
         $this->db->order_by('data', 'desc')
                ->limit($per_page, $offset);
         
        return $this->db->get('noticia');
     }
     
    
    public function get_count_noticias() {

        $this->db->select('n.*');
        $this->db->from('noticia as n');

        return $this->db->get()->num_rows();
    }
     
     
     public function get_all_news() {
        
         $this->db->order_by('id', 'desc');
         
        return $this->db->get('news');
     }
     
      public function get_noticias($offset = 3) {
        
        $this->db->select('n.*')
                ->from('noticia AS n')
                ->order_by("data", "desc")
                ->limit($offset);
         
        return $this->db->get();
     }
    
}

?>
