Home >php教程 >php手册 >文章阅读次数的记录与显示函数php

文章阅读次数的记录与显示函数php

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 10:24:071212browse


/*计数函数
$table 表名
$counname 计数存放字段
$idname ID字段名
$id 所查询的ID号
$view 保存还是查看数
作者:microrain
主页:http://www.codechina.net
Email:web@codechina.net
*/

function counter($table,$counname,$idname,$id,$view) {
//查询当前浏览数
$sql="select * from $table where $idname=$id";
$result=mysql_query($sql);
$objresult=mysql_fetch_object($result);
$count=$objresult->$counname;
//更新数据库,并反回当前浏览数作为结果
$count2=$count+1;
if($view){

$sql="update $table set $counname=$count2 where $idname=$id";
mysql_query($sql);
}
return $count2;
}
?>

Statement:
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