公益圖書館-OnshelfController-代碼學習

來源:互聯網
上載者:User

標籤: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("更新資訊失敗!"); } }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.