1 | public function hitsAction() { $id = (int) $this ->get( 'id' ); if ( empty ( $id )) exit ; $data = $this ->db->setTableName( 'content' )->find( $id , 'hits' ); $hits = $data [ 'hits' ] + 1; $this ->db->setTableName( 'content' )->update( array ( 'hits' => $hits ), 'id=?' , $id ); echo "document.write('$hits');" ; }
|
登入後複製
这个是我网上下载的一个CMS程序的一段控制文章阅读量的代码,我想在这段代码里面加上刷新或访问后,文章的时间字段(time)值更新为当前系统时间,请问需要怎么写呢,完全不会php,请大神详细点,先谢谢了
回复讨论(解决方案)
1 | public function hitsAction() { $id = (int) $this ->get( 'id' ); if ( empty ( $id )) exit ; $data = $this ->db->setTableName( 'content' )->find( $id , 'hits' ); $hits = $data [ 'hits' ] + 1; $t = time(); $this ->db->setTableName( 'content' )->update( array ( 'hits' => $hits , 'time' => $t ), 'id=?' , $id ); echo "document.write('$hits');" ;}
|
登入後複製
登入後複製
如果你的time字段是datetime类型
把$t = time(); 改位 $t=date('Y-m-d H:i:s');
如果time字段是int
则用上面的就可以了。
1 | public function hitsAction() { $id = (int) $this ->get( 'id' ); if ( empty ( $id )) exit ; $data = $this ->db->setTableName( 'content' )->find( $id , 'hits' ); $hits = $data [ 'hits' ] + 1; $t = time(); $this ->db->setTableName( 'content' )->update( array ( 'hits' => $hits , 'time' => $t ), 'id=?' , $id ); echo "document.write('$hits');" ;}
|
登入後複製
登入後複製
解决了,谢谢