|
thinkphp中setInc、setDec方法 可用于统计字段(通常是数字类型的字段)的更新,例如积分,等级,登陆次数等 必须配合连贯操作where一起使用 - $User = M("User"); // 实例化User对象
5 ]9 \8 T& c; l9 a( i - $User->where('id=5')->setInc('score',3); // 用户的积分加39 D( P) L, F& t3 @* J1 {
- $User->where('id=5')->setInc('score'); // 用户的积分加1
1 b: n8 o8 ~8 b% ?; Z4 _7 y - $User->where('id=5')->setDec('score',5); // 用户的积分减5
; q$ T3 F0 t# i. R8 a - $User->where('id=5')->setDec('score'); // 用户的积分减1
复制代码- $User = M( "User" ); // 实例化 User 对象
& g# b1 X* V" E# _* G -
: f$ ?4 E% R C6 L - $User->setInc( 'score','id=5',3 ); // 用户的积分加 3* X: o) U9 H! @5 i9 R
-
( ^$ x% @( s+ Q! z! T# e0 a- G8 g - $User->setInc( 'score','id=5' ); // 用户的积分加 1
. V H( Y- y3 i+ |5 d8 S# I - 6 w# u" w9 w0 U: J3 a. p% l
- $User->setDec( 'score','id=5',5 ); // 用户的积分减 5
6 @( x1 ^5 L3 K0 M6 ^5 x7 Q0 A - K5 ]& [2 p* v5 ?, V# d P9 L! ~
- $User->setDec( 'score','id=5' ); // 用户的积分减 1
复制代码- $data['login_count']=array('exp','login_count+1');
复制代码
: Q9 h3 `+ E9 `- y& C4 z
" @( Z* d& B5 n! a" H2 j. J- UPDATE user SET score=score+3 WHERE id = 5
复制代码 0 t- V; Z C! y3 G+ `
|