Advertisement
salim4rt

model_brands

May 21st, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <?php
  2.  
  3. class Model_brands extends CI_Model
  4. {
  5.     public function __construct()
  6.     {
  7.         parent::__construct();
  8.     }
  9.  
  10.     /*get the active brands information*/
  11.     public function getActiveBrands()
  12.     {
  13.         $sql = "SELECT * FROM brands WHERE active = ?";
  14.         $query = $this->db->query($sql, array(1));
  15.         return $query->result_array();
  16.     }
  17.  
  18.     /* get the brand data */
  19.     public function getBrandData($id = null)
  20.     {
  21.         if($id) {
  22.             $sql = "SELECT * FROM brands WHERE id = ?";
  23.             $query = $this->db->query($sql, array($id));
  24.             return $query->row_array();
  25.         }
  26.  
  27.         $sql = "SELECT * FROM brands";
  28.         $query = $this->db->query($sql);
  29.         return $query->result_array();
  30.     }
  31.    
  32.     public function create($data)
  33.     {
  34.         if($data) {
  35.             $insert = $this->db->insert('brands', $data);
  36.             return ($insert == true) ? true : false;
  37.         }
  38.     }
  39.  
  40.     public function update($data, $id)
  41.     {
  42.         if($data && $id) {
  43.             $this->db->where('id', $id);
  44.             $update = $this->db->update('brands', $data);
  45.             return ($update == true) ? true : false;
  46.         }
  47.     }
  48.  
  49.     public function remove($id)
  50.     {
  51.         if($id) {
  52.             $this->db->where('id', $id);
  53.             $delete = $this->db->delete('brands');
  54.             return ($delete == true) ? true : false;
  55.         }
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement