//控制器中
$kindlist = $this->kindgarten->getKindgartenList(); foreach($kindlist as $key=>$val) { $arr = explode(",",$val['kgPosition']); $updateArr = array( 'Lng'=>$arr[1], 'Lat'=>$arr[0] ); $this->kindgarten->addGarten($updateArr , $val['kgId']); }
model中
/** * @return mixed */ public function getKindgartenList() { $query = $this->db->get($this->table)->result_array(); return $query; } /** * 幼儿园数据入库 * */ public function addGarten($gartenData,$kgId){ if(empty($kgId)) { $gartenData['changeTime'] = time().'000'; $this->db->insert($this->table,$gartenData); return $this->db->insert_id(); } else { return $this->db->update($this->table,$gartenData,array('kgId'=>$kgId)); } }