<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Area_Model extends MY_Model {

    public $table = 'area';
    public function __construct()
    {
        parent::__construct();
    }

    public function area_insert($id,$name)
    {
        $data = array(
            'area_name' => $name,
            'id' =>$id
            );

        $this->db->insert($this->table, $data);
      
    }

    public function area_update($id,$name)
    {
        $data = array('area_name'=>$name);
        $this->db->where('id',$id);
        $this->db->update($this->table, $data); 
        return TRUE;
    }

    public function area_del($id)
    {
        $data = array('aid' => 0);

        $this->db->where('aid', $id);
        $this->db->update('shop', $data); 

        $this->db->delete($this->table, array('id' => $id));
    }

    public function area_count()
    {
        return $this->db->get($this->table)->num_rows();
    }
    public function area_list()
    {
        $this->db->order_by("id", "asc");
        return $this->db->get($this->table)->result_array();
    }

    public function checkdata($id)
    {
        return $this->db->get_where($this->table,array('id'=>$id))->num_rows();
    }

    public function getarea()
    {
        $this->db->order_by("id", "asc");
        $result = $this->db->get($this->table)->result_array();
        $rs = array();
        foreach ($result as $row) {
            $rs[$row['id']] = $row['area_name'];
        }
        return $rs;
    }

}