thinkphp Modify, delete data, show all

Source: Internet
Author: User

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

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.