统计账号user01所有发稿数::
{pc:get sql="SELECT count(*) as userconut FROM phpcms_news where username = 'user01' "}
{loop $data $key $r}
{$r[userconut]}
{/loop}
{/pc}
统计账号user01本年度(2016年)发稿数:
{pc:get sql="SELECT count(*) as userconut FROM phpcms_news where username = 'user01' and inputtime >= unix_timestamp('20160101000000') "}
{loop $data $key $r}
{$r[userconut]}
{/loop}
{/pc}
代码解释:
count(*) 是个聚合函数,作用是求表的所有记录数
select * from 表名 这个是查询表的所有记录
select count(*) from 表名 这个是查询表的所有记录数
user01 为后台管理员组内的账号,根据自己网站的实际情况替换
inputtime 发布时间
updatetime 更新时间
SQL统计法:
SELECT a.realname AS 姓名, c.catname AS 栏目名称, count(1) AS 发稿量
FROM phpcmsv9_bangzhu bz, phpcmsv9_category c, phpcmsv9_admin a
WHERE bz.inputtime >= UNIX_TIMESTAMP('20130101000000')
AND bz.inputtime <= UNIX_TIMESTAMP('20131231235959')
AND bz.islink = 0
AND bz.status = 99
AND bz.catid = c.catid
AND bz.username = a.username
GROUP BY bz.username, bz.catid
-- phpcmsv9_bangzhu 帮助中心模型表
-- phpcmsv9_category 栏目表
-- phpcmsv9_admin 后台管理员表
-- islink = 0 非跳转文章
-- status = 99 已发布文章
相关贴子:
http://bbs.phpcms.cn/thread-831875-1-1.html
|