<?php
/**
	by it308.com
*/
class Users_m extends CI_Model{
	public function __construct(){
		parent::__construct();
	}
	public function insert($data){
		$this->db->insert('users',$data);
		return $this->db->affected_rows();
	}
	public function get($where,$like=""){
		$this->db->where($where);
		if($like){
			$this->db->like('users.userword',$like,'after');
		}
		$res = $this->db->get('users')->result();
		//echo $this->db->last_query();
		return $res;
	}
	public function update($where,$data){
		$this->db->where($where);
		$this->db->update('users',$data);
		return $this->db->affected_rows();
	}
	public function delete($where){
		$this->db->where($where);
		$this->db->delete('users');
		return $this->db->affected_rows();
	}
	public function getID($where){
		$this->db->select('users.*,groups.name as gname,groups.id as gid');
		$this->db->join('groups', 'groups.id = users.group', 'left');
		$this->db->where($where);
		$res = $this->db->get('users')->result();
		return $res;
	}
	public function getLimit($where="",$like="",$begin=0,$count=0){
		$this->db->select('users.*,groups.name as gname');
		$this->db->join('groups', 'groups.id = users.group', 'left');
		$this->db->where($where);
		if($like){
			$this->db->like('users.userword',$like,'after');
		}
		$this->db->order_by('users.time desc');
		$this->db->limit($count,$begin);
		$res = $this->db->get('users')->result();
		//echo $this->db->last_query();
		return $res;
	}
}
