標籤:des style blog color os io 資料 cti
1、書籍上架 更新資料庫
$id = $_GET[‘id‘]; //書籍id$bookDB = D("Book"); //執行個體化資料表對象$data[‘status‘] = "ON_SHELF"; //準備修改的資料項目 把status變換為ON_SHELF$result = $bookDB->update(‘id=‘.$id,$data); //資料庫更新操作print_r($result);redirect("/onshelf/index");//直接跳回onshelf頁面
2、編輯書籍資訊
更新資料庫操作:
$res = $bookDB->update(‘id=‘.$id,$data);
若$res>0則更新成功;
若$res=0則資訊沒有改動;
若$res<0則更新失敗。
/** * @author lxd * @description 編輯完成跳轉函數 */ public function editfinish(){ if(!IS_POST){ $this->error("頁面不存在!"); } //判斷是否由POST提交編輯資訊 //1登入驗證 Util 未登入使用者不能直接進入編輯頁面 if(!validateLogin()){ $this->error("請先登入"); redirect("/login"); }// print_r($_POST);// die; $bookDB = D("Book"); if($_POST[‘ifonshelf‘]){ $data[‘status‘] = "ON_SHELF"; }
//從表單裡擷取修改後的資料存入數組,準備更新資料庫 $data[‘name‘] = $_POST[‘name‘]; $data[‘author‘] = $_POST[‘author‘]; $data[‘translator‘] = $_POST[‘translator‘]; $data[‘publish‘] = $_POST[‘publish‘]; $data[‘description‘] = $_POST[‘description‘]; $id = $_POST[‘id‘]; //該書籍的id $res = $bookDB->update(‘id=‘.$id,$data); if($res>0){ $this->success("恭喜你,更新資訊成功!","/onshelf/index"); }else if($res==0){ $this->error("資訊沒有改動!","/onshelf/index"); }else{ $this->error("更新資訊失敗!"); } }