123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- class Product_model extends MY_Model
- {
-
- private $table_name = 'product';
- private $orderby = 'addtime';
-
- 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()
- {
- $this->db->order_by($this->orderby, 'desc');
- $query = $this->db->get($this->table_name);
- return $query->num_rows() > 0 ? $query->result_array() : false;
- }
- public function max_ord()
- {
- $this->db->select('max(ord) as max_ord');
- $query = $this->db->get($this->table_name);
- $ret = $query->row_array();
- return $ret['max_ord'];
- }
- public function count()
- {
- $this->db->select('count(*) as count');
- $query = $this->db->get($this->table_name);
- $ret = $query->row_array();
- return $ret['count'];
- }
- public function get_list_by_type($type=0)
- {
- $this->db->where('type', $type);
- $this->db->order_by('addtime', 'desc');
- $query = $this->db->get($this->table_name);
- return $query->num_rows() > 0 ? $query->result_array() : false;
- }
- public function all_order_time()
- {
- $this->db->order_by('addtime', 'desc');
- $query = $this->db->get($this->table_name);
- return $query->num_rows() > 0 ? $query->result_array() : false;
- }
- }
|