Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn. You often need to add or subtract the counting fields of a data table. Let's take a look at the specific usage methods in ThinkPHP.
The simplest method is to automatically add 1 to the score using the following method:
M ('user')-> where ('Id = 5')-> setInc ('score ');Of course, you can also add more points:
M ('user')-> where ('Id = 5')-> setInc ('score ', 5 );Of course, the operation can be reduced by 1.
M ('user')-> where ('Id = 5')-> setDec ('score ');The setInc and setDec methods can only operate on one field separately. If your field addition and subtraction operations are to be updated with other fields, the expression update method is required. For example:
$ User = M ('user ');
$ User-> id = 5;
$ User-> nickname = 'thinkphp ';
$ User-> score = array ('exp ', 'score + 5 ');
$ User-> save ();Modifies the nickname and credits of user data with id 5.
$ User-> score = array ('exp ', 'score + 5 ');This code is called expression update.
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB