当前位置:Gxlcms > PHP教程 > thinkphp数据库问题,大家看到帮帮忙,还在加班处理这个问题,谢谢了

thinkphp数据库问题,大家看到帮帮忙,还在加班处理这个问题,谢谢了

时间:2021-07-01 10:21:17 帮助过:30人阅读

需求:在thinkPHP中,如何用代码去判断当ispass为1时,向数据库中插入successtime字段的时间戳。

这是数据库表:

我的代码是这样写的,然后是错误的,大家帮帮忙,谢谢了。
$rob=M('rob');
if($rob->where(array('ispass'=>1))){
$time=time();
$data['successtime']=$time;
$rob_success=$rob->add($data);
if($rob_success){
$this->success('插入成功!');
}
}


回复讨论(解决方案)

$rob=M('rob');$data = array('successtime'=>time());if($rob->where(array('ispass'=>1))->save($data) !== FALSE){    $this->success('插入时间成功');}else{    $this->error('插入失败!');}

$model->where("ispass=1")->setField("successtime",time());

$model->where("ispass=1")->setField("successtime",$_SERVER['REQUEST_TIME']);

人气教程排行