0801 am using TP framework to change database additions and deletions

Source: Internet
Author: User

3 ways to add data

function Text3 () {$m =d ("info");//1. Use array $attr = Array ("Code" = "p005", "name" = "Maenad", "Sex" =>true, "nation" = > "c004", "brithday" = "1198-9-6",    $r = $m->add ($attr);    Dump ($r);} function Text2 () {$m = D ("info"),//2.VR mode $m->code= "p008", $m->name= "Harmony", $m->sex=0; $m->nation= "n003"; $m- >brithday= "1998-5-21"; $r = $m->add ();//Directly call the method to write the parameter, the way is the array, no parameters, the way is the VR dump ($R);}

  

3. Automatic collection of Forms
$n =d ("Nation"), $attr = $n->select (), $this->assign ("Nation", $attr), if (Empty ($_post)) {$this->display (); }else{$m = D ("info"), $m->create ();//automatically collect data, name must correspond to column name $m->sex=$_post["Sex"]==0?false:true; $r = $m->add (        );        Dump ($R), if ($r) {$this->success ("Add Success", "text", 10),//Hint message, jump page}else{$this->error ("Add Failed", "text", 3); }}//text.html Display the page code, create the Text directory under the View folder, <body><form action= "__action__" method= "POST" > <div> code &L T;input type= "text" name= "code" ></div> <div> name <input type= "text" name= "name" ></div> <d iv> sex <input type= "Radio" name= "Sex" checked= "checked" value= "1" > Male <input type= "Radio" name= "Sex" value= "0"                > Women </div> <div> National <select name= "Nation" > <foreach name= "Nation" item= "V" > <option value= "<{$v .code}>" ><{$v .name}></option> </foreach> </sel ect> </div> <div> Birthdays<input type= "text" name= "Brithday" ></div> <div><input type= "Submit" value= "Submit" ></div> </form></body>

modify  

TextController.class.php code function Xiugai () {$n =d ("Nation"), $attr = $n->select (); $th Is->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 Display the page code, create the Xiugai directory under the View folder; <body><form action= "__action__" method= "POST" > <input Type= "hidden" name= "code" value= "<{$info .code}>" > <div> name <input type= "text" name= "name" value= "  <{$info .name}> "></div> <div> gender <if condition=" $info. Sex eq 1 "> <input type=" Radio " Name= "Sex" checked= "checked" > Male <input type= "Radio" name= "Sex" > Female <else/> <input type= "Radio" name= "Sex" > Male <input type= "Radio" name= "Sex" checked= "checked" > Women </if> </div> <div> National <{$info .nation}> &Lt;select name= "Nation" > <foreach name= "Nation" item= "V" > <if condition= "$info. Nati On EQ $v. Code ">" Built-in label if "<option value=" <{$v .code}> "selected=" selected "><{$v. NAME}&GT;&L t;/option> <else/> <option value= "<{$v .code}>" ><{$v. name}></o ption> </if> </foreach> </select> </div> <div> Birthday <input type= "text" name= "Brithday" value= "<{$info .brithday}>" ></div> <div><input type= "Submit" value= "id=" btn "></div></form><input type=" button "id=" AA "value=" hahaha "></body >

 Delete

function Shanchu () {$m =d ("info");//$m->where ("code= ' p088 '")->delete ();    $m->where ("nation= ' n001 '")->delete (); $m->delete ("p003");}

 

0801 am using TP framework to change database additions and deletions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.