$User->where('id=5')->setDec('score',5);
D:\LearnWebDevelop\php\thinkphp_3.2.3_full\Application\Home\Controller\UserController.class.php
<?php namespace Home\Controller; use Think\Controller; class UserController extends Controller{ //下面是一个标准的URL访问格式: //http://serverName/index.php/模块/控制器/操作(/参数名/参数值) //http://localhost/thinkphp323/index.php/home/Form/add //http://localhost/thinkphp323/index.php/home/index/hello/name/baby //http://localhost/thinkphp323/index.php/home/User/inc_score?id=1&value=1 public function inc_score($id=1,$value=1){ $User = M("User"); // 实例化User对象 $User->where('id=' . $id)->setInc('score',(int)$value); // 用户的积分加 } //http://localhost/thinkphp323/index.php/home/User/dec_score?id=1&value=1 public function dec_score($id=1,$value=1){ $User = M("User"); // 实例化User对象 $User->where('id=' . $id)->setDec('score',(int)$value); // 用户的积分加 } //$User = M("User"); // 实例化User对象 //$User->where('id=5')->setInc('score',3); // 用户的积分加3 //$User->where('id=5')->setInc('score'); // 用户的积分加1 //$User->where('id=5')->setDec('score',5); // 用户的积分减5 //$User->where('id=5')->setDec('score'); // 用户的积分减1 }
CREATE TABLE IF NOT EXISTS `think_user` ( `id` smallint(4) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(255) NOT NULL, `score` INTEGER NOT NULL, `create_time` int(11) unsigned NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

浙公网安备 33010602011771号