<?php
class User_model extends CI_Model {

    public function __construct()
    {
        $this->load->database();
    }
    
    public function get_user()
    {  
        $this->db->order_by ( 'user_id', "desc" );
        $query = $this->db->get('user');
         return $query->result ();
    }    
    
    public function get_role()
    {
        $query = $this->db->get('role');
        return $query->result ();
    }    

    public function get_one_user($_id){
        $query = $this->db->get_where('user', array('user_id' => $_id));
        return $query->row_array();
    }
    
    public function get_user_name($_name){
        $query = $this->db->get_where('user', array('user_name' => $_name));
        return $query->row_array();
    }    
    
    public function update_user($_id,$_data){
        $this->db->where('user_id',$_id);
        $this->db->update("user",$_data);
        return $this->db->affected_rows();
    }
    public function add_user($_data){
        $this->db->insert("user",$_data);
        return $this->db->affected_rows();
    }    
}

