Home > Backend Development > PHP Tutorial > 想在阅读量增加代码中加一个“更新时间”

想在阅读量增加代码中加一个“更新时间”

WBOY
Release: 2016-06-20 12:54:56
Original
1141 people have browsed it

	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');";	}
Copy after login



这个是我网上下载的一个CMS程序的一段控制文章阅读量的代码,我想在这段代码里面加上刷新或访问后,文章的时间字段(time)值更新为当前系统时间,请问需要怎么写呢,完全不会php,请大神详细点,先谢谢了


回复讨论(解决方案)

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');";}
Copy after login
Copy after login

如果你的time字段是datetime类型
把$t = time(); 改位 $t=date('Y-m-d H:i:s');
如果time字段是int
则用上面的就可以了。

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');";}
Copy after login
Copy after login



解决了,谢谢
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template