Discuz! X 插件开发,数据查询表 - 数据调用代码教程

2021-03-16 942 0条评论



调用最新主题

$new=DB::fetch_all("SELECT tid,subject FROM ".DB::table('forum_thread')." ORDER BY `dateline` desc LIMIT 0,1;");




调用最新主题封面图


$img=DB::fetch_all("SELECT a.subject,a.tid,b.attachment FROM ".DB::table("forum_thread")." a LEFT JOIN ".DB::table("forum_threadimage")." b on b.tid=a.tid WHERE a.`attachment`=2 ORDER BY a.`dateline` DESC LIMIT 0,5");



调用当前登录用户阅读权限


$read=DB::result(DB::query("SELECT b.readaccess FROM ".DB::table('common_member')." a left join ".DB::table('common_usergroup_field')." b on b.groupid=a.groupid WHERE a.`uid`= '$_G[uid]'"));



调用常用统计数据




//获取VERSION、RELEASE

$version = unserialize($_G['setting']['cloudaddons_newversion']);


//获取站长用户名

$name = DB::result_first("select username from ".DB::table("common_member")." where uid = 1");


//获取建站时间

$time = DB::result_first("select regdate from ".DB::table("common_member")." where uid = 1");


//获取模板个数

$templates = DB::result_first("select count(styleid) from ".DB::table("common_style")."");


//获取插件个数

$plugins = DB::result_first("select count(pluginid) from ".DB::table("common_plugin")."");


//获取会员人数

$users = DB::result_first("select count(uid) from ".DB::table("common_member")."");


//获取临时会员人数

$guests = DB::result_first("select count(conopenid) from ".DB::table("common_connect_guest")."");


//获取会员总人数

$all_users = $users + $guests;


//获取管理团队人数

$admins = DB::result_first("select count(uid) from ".DB::table("common_member")." where groupid in (1,2)");


//获取最新注册会员

$newuser = DB::result_first("select username from ".DB::table("common_member")." order BY regdate desc");


//获取发帖会员人数

$post_posts = DB::result_first("select count(uid) from ".DB::table("common_member_count")." where posts > 0 ");


//获取发表主题会员人数

$post_threads = DB::result_first("select count(uid) from ".DB::table("common_member_count")." where threads > 0 ");


//获取版块数

$forums = DB::result_first("select count(fid) from ".DB::table("forum_forum")." where type = 'forum' and status in (0,1)");


//获取总帖数

$posts = DB::result_first("select count(pid) from ".DB::table("forum_post")."");


//获取主题数

$threads = DB::result_first("select count(tid) from ".DB::table("forum_thread")."");


//获取精华主题数

$digest = DB::result_first("select count(digest) from ".DB::table("forum_thread")." where digest > 0");


//获取高亮主题数

$highlight = DB::result_first("select count(highlight) from ".DB::table("forum_thread")." where highlight > 0");


//获取置顶主题数

$displayorder = DB::result_first("select count(displayorder) from ".DB::table("forum_thread")." where displayorder > 0");


//获取附件主题数

$attachment = DB::result_first("select count(tid) from ".DB::table("forum_thread")." where attachment > 0");


//获取待审核主题数

$moderate_threads = DB::result_first("select count(id) from ".DB::table("forum_thread_moderate")." where status = 0");


//获取已忽略主题数

$moderate_ignore_threads = DB::result_first("select count(id) from ".DB::table("forum_thread_moderate")." where status = 1");


//获取待审核回复数

$moderate_posts = DB::result_first("select count(id) from ".DB::table("forum_post_moderate")." where status = 0");


//获取已忽略回复数

$moderate_ignore_posts = DB::result_first("select count(id) from ".DB::table("forum_post_moderate")." where status = 1");


//获取主题回收站数

$recyclebin_threads = DB::result_first("select count(tid) from ".DB::table("forum_thread")." where displayorder = -1");


//获取回复回收站数

$recyclebin_posts = DB::result_first("select count(tid) from ".DB::table("forum_post")." where invisible = -5");


//获取访问总数

$views = DB::result_first("select sum(views) from ".DB::table("forum_thread")."");


//获取回复总数

$replies = DB::result_first("select sum(replies) from ".DB::table("forum_thread")."");


//获取支持总数

$recommend_add = DB::result_first("select sum(recommend_add) from ".DB::table("forum_thread")."");


//获取反对总数

$recommend_sub = DB::result_first("select sum(recommend_sub) from ".DB::table("forum_thread")."");


//获取收藏总数

$favtimes = DB::result_first("select sum(favtimes) from ".DB::table("forum_thread")."");


//获取分享总数

$sharetimes = DB::result_first("select sum(sharetimes) from ".DB::table("forum_thread")."");


//获取会员:男性

$users_man = DB::result_first("select count(uid) from ".DB::table("common_member_profile")." where gender = 1 ");


//获取会员:女性

$users_woman = DB::result_first("select count(uid) from ".DB::table("common_member_profile")." where gender = 2 ");


//获取会员:80后

$users_80 = DB::result_first("select count(uid) from ".DB::table("common_member_profile")." where birthyear > 1980 and birthyear < 1989 ");



<!--{eval
        $usernum = DB::result_first("SELECT count(*) FROM ".DB::table('common_member'));  //会员数
        $onlinenum = DB::result_first("SELECT count(*) FROM ".DB::table('common_session'));  //在线会员数  or // $onlinenum = C::app()->session->count();
        $todayposts = DB::result_first("SELECT sum(todayposts) FROM ".DB::table('forum_forum')." WHERE status=1");  //今日发帖数
        $yesterdayposts = DB::result_first("SELECT sum(yesterdayposts) FROM ".DB::table('forum_forum')." WHERE status=1");  //昨日发帖数
        $posts = DB::result_first("SELECT sum(posts) FROM ".DB::table('forum_forum')." WHERE status=1");  //总帖子数
}-->




//待审核会员数

$membersmod = C::t('common_member_validate')->count_by_status(0);


//回收站的主题数

$threadsdel = C::t('forum_thread')->count_by_displayorder(-1);


//待审核群组

$groupmod = C::t('forum_forum')->validate_level_num();








文章版权及转载声明

本文作者:符文浩 网址:http://blog.fuwenhao.com/post/362.html 发布于 2021-03-16
文章转载或复制请以超链接形式并注明出处。

发表评论

快捷回复:

评论列表 (暂无评论,942人围观)参与讨论

还没有评论,来说两句吧...

取消
微信二维码
微信二维码
支付宝二维码