相关统计

来源:官方· 作者 jizhicms· 45次点击 · 5个月前

统计

经常会在模板中用到统计,那么做各种数据的统计呢?那么我就在本篇文章中详细讲解各种统计


统计核心思路

运用 M('模块标识')->getCount($sql) 进行计算

统计栏目文章数量

公式:M('模型标识')->getCount(['isshow'=>1,'tid'=>栏目ID])


统计当前栏目的文章数量(不包含子栏目)

当前栏目模型标识:$type['molds']

这个标识是根据后台栏目绑定的模型来定的,如果是内容模型,那么它就是 article

{fun M($type['molds'])->getCount(['isshow'=>1,'tid'=>$type['id']])}

统计当前栏目的文章数量(包含所有子栏目)

当前栏目模型标识:$type['molds']

这个标识是根据后台栏目绑定的模型来定的,如果是内容模型,那么它就是 article

{php

$tids = $classtypedata[$type['id']]['children']['ids'];//本级和所有下级ID
$sql = 'isshow=1 and tid in('.implode(',',$tids).') ';
$count = M($type['molds'])->getCount($sql);

/}

{$count}


由于刚好是栏目列表,所以,根据分页数据又可以写成: {$sum}


如果在其他页面,需要指定某个栏目的内容数量,代码如下:

假设栏目ID=1

{php

$tids = $classtypedata[1]['children']['ids'];//本级和所有下级ID
$sql = 'isshow=1 and tid in('.implode(',',$tids).') ';
$count = M($type['molds'])->getCount($sql);

/}

{$count}


统计用户发布的文章数

假设这个用户 ID=2

{fun M('article')->getCount(['isshow'=>1,'member_id'=>2])}

如果是当前用户呢?

{fun M('article')->getCount(['isshow'=>1,'member_id'=>$member['id']])}


被收藏 0  ∙  1 赞  
加入收藏
0 回复  
善言善语 (您需要 登录 后才能回复 没有账号 ?)

请先登录网站