<?phpnamespace Home\Controller;use Think\Controller;class IndexController extends Controller {public function index(){ $Users=D("users"); $attr=$Users->select(); $this->assign("canshu",$attr); $this->display(); dump($Users->select()); } function delete($user_id) { $Users=D("Users"); $r=$Users->delete($user_id); if($r) { $this->success("刪除成功",U("index")); } else { $this->error("刪除失敗"); } } function insert(){ $Users = D('Users'); if($Users->create()) { $result = $Users->add(); if($result) { $this->success("數據添加成功!",U("index")); }else{ $this->error('數據添加錯誤!'); } }else{ $this->error($Users->getError()); } } function edit($id=0){ $Users = M('Users'); $this->assign('vo',$Users->find($user_id)); $this->display(); } function update(){ $Users = D('Users'); if($Users->create()) { $result = $Users->save(); if($result) { $this->success('操作成功!',U("index")); }else{ $this->error('寫入錯誤!'); } }else{ $this->error($Users->getError()); } }}
1 回答

湖上湖
TA貢獻2003條經驗 獲得超2個贊
你是要將查詢出的數據中為空的字段補充信息,這樣可能有好幾個空字段,所以理想的方法是先找出需要更新的字段,最后再一次性更新。
foreach($arr[0] as $k => $val){ $data['id'] = $arr[0]['id']; if($val == null) $data[$k] = '寫入這句'; $m->save($data); }
- 1 回答
- 0 關注
- 1721 瀏覽
添加回答
舉報
0/150
提交
取消