/**
* ThinkPHP 万能统计 v1.1 (作者:小曾)
* @param $table 数据库表名
* @param $where 查询条件 支持字符串或数组
* @param $field 查看字段 传入字段将统计此字段的总值
* @return 返回数字 无结果返回0
*/
function get_count($table,$where="",$field=""){
$db = M($table);
if($field){
$count = $db->where($where)->sum($field);
}else{
$count = $db->where($where)->count();
}
return $count ? $count : 0;
}
//使用示例
//统计用户总数
get_count('user');
//统计vip用户数
get_count('user','vip=1'); 或 get_count('user',array('vip'=>1));
//统计文章总点击量
get_count('article','','click');
//统计未审核的文章数
get_count('article','audit=0'); 或 get_count('article',array('audit'=>0));
//也可以在模板里使用
本的已有会员: {:get_count('user')} 人
//交流QQ群324098841
//论坛 http://www.flash127.com
Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1
| 本站CDN由 数掘科技 提供