<?php

class Consultazione_macchinario_model extends CI_Model {

    public function __construct() {
        $this->load->helper('file');
        parent::__construct();
    }

    public function inserisci_riga($tabella, $riga) {
        if ($this->db->insert($tabella, $riga)) {
            return TRUE;
        } else {
            return FALSE;
        }
    }

    public function count_all($tabella,$where=null) {
         $this->db->select('count(*) as numrows');
         $this->db->from($tabella);
         if(!empty($where))
         $this->db->where($where);

        $query = $this->db->get();
                //echo $this->db->last_query();

        return $query->row()->numrows;
    }

    public function get_record($ordinamento, $tabella, $riga = null, $limit = null, $offset = null) {
        
        if(!empty($ordinamento))
        {
          $query = $this->db->order_by($ordinamento)->get_where($tabella, $riga, $limit, $offset);
          return $query->result();
        }
        else
        {
            $query = $this->db->get_where($tabella, $riga, $limit, $offset);
            return $query->result();
        }

        // $query = $this->db->get_where($tabella, $riga, $limit, $offset);
        // echo $this->db->last_query();
        // die();
    }

}

?>
