/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
class News_model extends Model { function News_model(){ parent::Model(); $this->table = 'news'; $this->order = 'post_date desc'; } foreach($this->fields as $field){ $this->$field = null; } } function select(){ $result = false; foreach($this->fields as $field){ if($this->$field){ $this->db->where($field, $this->$field); } } $this->db->order_by($this->order); $query = $this->db->get($this->table); if($this->post_id){ $result = $query->row(); } else{ $result = $query->result(); } return $result; } function update(){ $result = false; foreach($this->fields as $field){ $entry[$field] = $this->$field; } if($this->post_id){ $this->db->update($this->table, $entry); } else{ $this->db->insert($this->table, $entry); } return $result; } function insert(){ return $this->update(); } function delete(){ if($this->post_id){ $this->db->delete($this->table); } } } ?>