<?php 
class Common_model extends CI_Model
{
    /*
     * Construct
     */
	public function __construct()
    {
        parent::__construct();
    }
	public function Insert($table, $data)
    {
        $query = $this->db->insert($table, $data);
        if ($query) {
            $insert_id = $this->db->insert_id();
            return $insert_id;
        } else {
            return false;
        }
    }



    public function count_all($search = null) {
    if (!empty($search)) {
       $this->db->like('f_name', $search);
        $this->db->or_like('user_id', $search);
        $this->db->or_like('email_id', $search);
        $this->db->or_like('mobile_no', $search);
    }
    return $this->db->count_all_results('tbl_user');
}



public function get_paginated($limit, $offset, $search = null) {
    if (!empty($search)) {
        $this->db->like('f_name', $search);
        $this->db->or_like('user_id', $search);
        $this->db->or_like('email_id', $search);
        $this->db->or_like('mobile_no', $search);
    }
    $this->db->order_by('tbl_user.id', 'DESC');
    return $this->db->limit($limit, $offset)->get('tbl_user')->result();
}










    public function Update($table, $data, $where = 0)
    {
        
        if ($where != 0) {
            $this->db->where($where);
        }
        $query = $this->db->update($table, $data);
        if ($query) {
            return true;
        } else {
            return false;
        }
    }

    public function Delete($table, $where = 0)
    {
        if ($where != 0) {
            $this->db->where($where);
        }
        $query = $this->db->delete($table);
        if ($query) {
            return true;
        } else {
            return false;
        }
    }
}
?>