0801 am使用tp框架对数据库增删改查
生活随笔
收集整理的這篇文章主要介紹了
0801 am使用tp框架对数据库增删改查
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
增添數據,3種方法 ? ? ? ? ? ? ? ?
function Text3() { $m=D("info"); //1.使用數組 $attr = array( "code"=>"p005", "name"=>"李師師", "sex"=>true, "nation"=>"c004", "brithday"=>"1198-9-6",); $r=$m->add($attr);dump($r); }function Text2() { $m = D("info"); //2.VR方式 $m->code="p008"; $m->name="和諧"; $m->sex=0; $m->nation="n003"; $m->brithday="1998-5-21"; $r=$m->add(); //直接調用該方法寫參數,方式是數組的,沒有參數,方式是VR的 dump($r); }//3.自動收集表單 $n=D("nation"); $attr=$n->select(); $this->assign("nation",$attr);if(empty($_POST)){ $this->display();} else { $m = D("info"); $m->create();//自動收集數據,name一定和列名對應起來 $m->sex=$_POST["sex"]==0?false:true; $r=$m->add();dump($r); if($r){ $this->success("添加成功","Text",10);//提示信息,跳轉頁面 } else { $this->error("添加失敗","Text",3);}} } //Text.html 顯示頁面代碼,在view文件夾下創建Text目錄; <body> <form action="__ACTION__" method="post"><div>代號<input type="text" name="code"></div><div>姓名<input type="text" name="name"></div><div>性別 <input type="radio" name="sex" checked="checked" value="1">男 <input type="radio" name="sex" value="0">女 </div><div>民族 <select name="nation"><foreach name="nation" item="v"><option value="<{$v.code}>"><{$v.name}></option></foreach></select></div><div>生日<input type="text" name="brithday"></div><div><input type="submit" value="提交"></div> </form> </body>
修改?
//TextController.class.php 代碼 function XiuGai() { $n=D("nation"); $attr=$n->select(); $this->assign("nation",$attr); $code=$_GET["code"]; $m=D("info"); if(empty($_POST)){ $attr=$m->find($code); var_dump($attr); $this->assign("info",$attr); $this->display();} else { $m->create(); $m->sex=$_POST["sex"]==0?false:true; $m->save();} } //XiuGai.html 顯示頁面代碼,在view文件夾下創建XiuGai目錄; <body> <form action="__ACTION__" method="post"><input type="hidden" name="code" value="<{$info.code}>"><div>姓名<input type="text" name="name" value="<{$info.name}>"></div><div>性別 <if condition="$info.sex eq 1" ><input type="radio" name="sex" checked="checked">男 <input type="radio" name="sex">女 <else /><input type="radio" name="sex">男 <input type="radio" name="sex" checked="checked">女 </if></div><div>民族 <{$info.nation}><select name="nation"><foreach name="nation" item="v"><if condition=" $info.nation eq $v.code ">【內置標簽If】<option value="<{$v.code}>" selected="selected"><{$v.name}></option><else /><option value="<{$v.code}>"><{$v.name}></option></if></foreach></select></div><div>生日<input type="text" name="brithday" value="<{$info.brithday}>"></div><div><input type="submit" value="提交" id="btn"></div> </form> <input type="button" id="aa" value="哈哈哈"> </body>刪除 ? ? ? ? ??
function ShanChu() { $m=D("info"); //$m->where("code='p088'")->delete();//$m->where("nation='n001'")->delete(); $m->delete("p003"); }
轉載于:https://www.cnblogs.com/pangchunlei/p/5731555.html
總結
以上是生活随笔為你收集整理的0801 am使用tp框架对数据库增删改查的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用Spring Security3的四
- 下一篇: 关于.net的.dll.refresh文