<?php

class Equip_m extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function get_all($txtsearch, $offset, $per_page = 20, $url = '/equip/ajax_get_grid') {
        if ($txtsearch != '') {
            $this->db->like('name', $txtsearch);
            $this->db->or_like('detail', $txtsearch);
        }
        $total = $this->db->get('tbequip')->num_rows();

        if ($txtsearch != '') {
            $this->db->like('name', $txtsearch);
            $this->db->or_like('detail', $txtsearch);
        }
        $this->db->limit($per_page, $offset);
        $this->db->order_by('name', 'asc');
        $query = $this->db->get('tbequip')->result_array();

        $this->load->library('pagination');
        $data['pagination'] = $this->pagination->pagin($total, $url, $per_page);
        $data['query'] = $query;
        return $data;
    }

    //get ชื่ออุปกรณ์
    function get_equipname($equip_id) {
        $this->db->where('id', $equip_id);
        $row = $this->db->get('tbequip')->row_array();

        if (isset($row['id'])) {
            return $row['name'];
        } else {
            return '';
        }
    }

}

?>
