1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- class Example_model extends MY_Model
- {
-
- private $table_name = 'example';
- private $orderby = 'ord';
-
- public function insert($parm)
- {
- $this->db->insert($this->table_name, $parm);
- return $this->db->insert_id();
- }
- public function delete($id) {
- $this->db->where('id', $id);
- $this->db->delete($this->table_name);
- return $this->db->affected_rows();
- }
-
- public function update($id, $parm) {
- $this->db->where('id', $id);
- $this->db->update($this->table_name, $parm);
- return $this->db->affected_rows();
- }
- public function get($id)
- {
- $this->db->select('*');
- $this->db->from($this->table_name);
- $this->db->where('id', $id);
- $query = $this->db->get();
- return $query->num_rows() > 0 ? $query->row_array() : false;
- }
-
- public function all($type)
- {
- $this->db->where('type', $type);
- $this->db->order_by($this->orderby, 'asc');
- $query = $this->db->get($this->table_name);
- return $query->num_rows() > 0 ? $query->result_array() : false;
- }
- public function max_ord($type)
- {
- $this->db->where('type', $type);
- $this->db->select('max(ord) as max_ord');
- $query = $this->db->get($this->table_name);
- $ret = $query->row_array();
- return $ret['max_ord'];
- }
- }
|