1, modify the data
1 //Data Modification2 functionUpdate ()3 {4 $model= D ("info");5 6 /*7 //1, array mode8 $attr = Array (9 "Code" = "P001",Ten "Name" = "Zhang San", One "Sex" =>true, A " Nation" = "n001", - "Birthday" = "1998-3-2 " - ); the - //Call the Save method to modify the data - $model->save ($attr); - */ + - /* + //2,ar Way A $model->name= "Harry"; at $model->nation= "n003"; - - $model->where ("Code = ' p0012 '")->save (); - */ - - //3, Automatic collection of forms in if(Empty($_post)) - { to $code= "P002"; + $attr=$model->find ($code); - $this->assign ("Shuju",$attr); the * $this-display (); $ }Panax Notoginseng Else - { the $model-Create (); + $model-Save (); A } the +}
2. Delete data
// data delete function Delete () { // Delete data $model = D ("info" // delete
$model
->delete ("p0012" ); // delete $model ->where ("Name= ' Cjke '")-> delete (); }
3, table display data
Note: When the two table member variable names (column names) of a join are the same, they are prone to confusion and the output is modified with as field name
1 //methods for displaying all data2 functionShowinfo ()3 {4 $model= D ("Info");5 $attr=$model->field ("Info.code as infocode,info.name as Infoname,info.sex,
Nation.name as Nationname,info.birthday ")Join("Nation on Info.nation=nation.code")Select ();
6 $this->assign ("Shuju",$attr);7 $this-display ();8}
Showinfo.html
1 <Body>2 <H1>Main Page</H1>3 4 <TableBorder= "1"width= "100%"cellpadding= "0"cellspacing= "0">5 <TR>6 <TD>Code</TD>7 <TD>Name</TD>8 <TD>Gender</TD>9 <TD>National</TD>Ten <TD>Birthday</TD> One <TD>Operation</TD> A </TR> - - <foreachname= "Shuju"Item= "V"> the <TR> - <TD><{$v. Infocode}></TD> - <TD><{$v. InfoName}></TD> - <TD><{$v["Sex"]= = "1"? " Male ":" Female "}></TD> + <TD><{$v. Nationname}></TD> - <TD><{$v. Birthday}></TD> + <TD> A <ahref= "__controller__/xiugai/code/<{$v .infocode}>" >Modify</a> at <ahref= "__controller__/shanchu/code/<{$v .infocode}>">Delete</a> - </TD> - </TR> - </foreach> - - </Table> in - </Body> to </HTML>
thinkphp Modify, delete data, show all