收起左侧

Discuz数据库调用:DZ模板调用常用代码手册

[复制链接]
网站编辑 发表于 2019-9-14 10:45:12
登录
  1. <a href="member.php?mod=logging&action=login" οnclick="showWindow('login', this.href);return false;" title="登录">登录</a>
复制代码
注册

  1. <a href="member.php?mod=register" title="立即注册">立即注册</a>
复制代码
忘记密码

  1. <a href="javascript:;" οnclick="showWindow('login', 'member.php?mod=logging&action=login&viewlostpw=1')" title="找回密码">找回密码</a>
复制代码
购买邀请码

  1. misc.php?mod=buyinvitecode
复制代码
JS跳转

  1. οnclick="window.location.href='home.php?mod=mobile&do=friend';"
复制代码
JS更换class的名称
  1. document.getElementById('idname').className='a';
  2. document.getElementById('idname').style.display='block';
  3. document.getElementById("idname").style.marginTop="30px";
复制代码


批量替换超链接:
  1. href="[^"]*"
复制代码
过滤DZ代码
  1. preg_replace ("/\[[a-z][^\]]*\]|\[\/[a-z]+\]/i",'',preg_replace("/\[attach\]\d+\[\/attach\]/i",'',$message));
复制代码

调用单个数据
  1. $qishi = DB::result(DB::query("SELECT qi FROM ".DB::table('jiangchi')." WHERE id = '1'"));
复制代码
调用统计数据
  1. $qishi = DB::result(DB::query("SELECT count(*) FROM ".DB::table('jiangchi')." WHERE id = '1'"));
复制代码
单数据表调用
  1. $perpage = 20;
  2. $curpage = empty ( $_GET['page'] ) ? 1 : intval ( $_GET['page'] );
  3. $start = ($curpage-1)*$perpage;
  4. $askcount = DB::result(DB::query("SELECT COUNT(*) FROM ".DB::table('forum_thread')." WHERE fid = '2' AND authorid > 1 AND FROM_UNIXTIME(dateline, '%Y%m%d') = '$jintian'"));
  5. //$asklist
  6. $asklist = array();
  7. if ($askcount) {
  8. $query = DB::query("SELECT * FROM ".DB::table('forum_thread')." WHERE fid = '2' AND displayorder > -1 ORDER BY tid ASC LIMIT $start,$perpage");
  9. while ($value = DB::fetch($query)) {
  10. $asklist[] = $value;
  11. }
  12. }
  13. $multi = multi($askcount, $perpage, $curpage, "portal.php?mod=topic&topic=ask");
复制代码
多数据表调用
  1. $perpage = 40;
  2. $curpage = empty ( $_GET['page'] ) ? 1 : intval ( $_GET['page'] );
  3. $start = ($curpage-1)*$perpage;
  4. $acount = DB::result(DB::query("SELECT count(*) FROM ".DB::table('forum_forum')." b LEFT JOIN ".DB::table('forum_forumfield')." bf ON bf.fid=b.fid WHERE b.type='sub' AND b.status = 3 AND bf.icon != ''"));
  5. //$alist
  6. $alist = array();
  7. if ($acount) {
  8. $query = DB::query("SELECT bf.*, b.* FROM ".DB::table('forum_forum')." b LEFT JOIN ".DB::table('forum_forumfield')." bf ON bf.fid=b.fid WHERE b.type='sub' AND b.status = 3 AND bf.icon != '' ORDER BY bf.shoplevel DESC, b.commoncredits DESC, bf.fid DESC LIMIT $start,$perpage");
  9. while ($value = DB::fetch($query)) {
  10. $alist[] = $value;
  11. }
  12. }
  13. $multi = multi($acount, $perpage, $curpage, "这里填写跳转地址");
复制代码
前台数据显示
  1. <!--{loop $alist $key $value}-->
  2. <!--{eval $tupianfm = DB::result(DB::query("SELECT attachment FROM ".DB::table('forum_threadimage')." WHERE tid = '$value[tid]'"));}-->
  3. $value[authorid]
  4. <!--{/loop}-->
复制代码
取数据表中符合条件的第一条数据
  1. $app=array();
  2. $app=DB::fetch_first("select * from ".DB::table('home_diy_center')." where id='{$id}'");
复制代码
人性化时间戳
  1. <!--{echo dgmdate(这里填写时间参数, 'u', '9999', getglobal('setting/dateformat'))}-->
  2. <!--{echo date("Y-m/d H:i:s",这里填写时间参数)}-->
复制代码
截取字符字数
  1. <!--{echo cutstr(这里填写参数,40)}-->
复制代码
过滤DISCUZ代码
  1. preg_replace ("/\[[a-z][^\]]*\]|\[\/[a-z]+\]/i",'',preg_replace("/\[attach\]\d+\[\/attach\]/i",'',$message));
复制代码
写入数据库
  1. if(submitcheck('tijiao')) {
  2. $setarr = array(
  3. 'tid' => $_GET['topicid'],
  4. 'name' => $_POST['name'],
  5. 'position' => $_GET['position'],
  6. 'dateline' => $_G['timestamp'],
  7. );
  8. DB::insert('forum_poststick', $setarr, 1);
  9. $query = DB::query("UPDATE ".DB::table('forum_thread')." SET stickreply='1'
  10. WHERE tid='$tid'");
  11. $query = DB::query("DELETE FROM ".DB::table('forum_post')." WHERE pid='$pid'");
  12. showmessage('成功的提示信息', "forum.php?mod=viewthread&tid=$tid");
  13. }
复制代码
表单提交:
  1. <form action="do.php?op=jiangchi&con=yes" method="post" autocomplete="off">
  2. <input type="hidden" value="{FORMHASH}" name="formhash" />
  3. 最低奖金:<input name="qi" type="text" value="$qishi" /> 
  4. 最高奖金:<input name="end" type="text" value="$zhzh" />  
  5. <button value="true" name="tijiao" type="submit">提交设置</button>
  6. <input type="hidden" name="tijiao" value="true" />
  7. </form>
复制代码
以下两个时间格式是对等关系
  1. date("Ymd",time()); 20150212
  2. FROM_UNIXTIME(dateline, '%Y%m%d')
复制代码


前者用于PHP,后者用于数据库调用的字段的格式化

调用图片附件
  1. <!--{eval $biaoid = substr($value[tid], -1); $cover = DB::result(DB::query("SELECT attachment FROM ".DB::table('forum_attachment_'.$biaoid.'')." WHERE tid = '$value[tid]'"));}-->
复制代码
数据库循环嵌套调用
  1. <!--{eval $slides = DB::fetch_all("SELECT * FROM ".DB::table('a')." WHERE `uid`= $_G[uid] ORDER BY `id` DESC");}-->
  2. <!--{loop $slides $slide}-->
  3. $slide[name]
  4. <!--{/loop}-->
复制代码

ucenter无法登录:
  1. 打开uc_server/model/admin.php
  2. 找到第22行的
  3. $this->cookie_status = 0;
  4. 改成
  5. $this->cookie_status = isset($_COOKIE['sid']) ? 1 : 0;
复制代码
无刷新切换li标签并且同时加载框架页面:

  1. var jq = jQuery.noConflict();
  2. jq(function(){
  3. jq("#changemenu>li").mouseover(function(){
  4. jq("#changemenu>li").each(function(i){
  5. jq(this).removeClass("current");
  6. });
  7. jq(this).addClass("current");
  8. document.getElementById("changenr").innerHTML='<iframe src="chart.php?op=index&id='+jq(this).attr('dataid')+'" height="350" width="1070" frameborder="0" scrolling="no"></iframe>';
  9. }).mouseout(function(){
  10. jq(this).addClass("current");
  11. });
  12. });
  13. </script>
  14. <ul id=“changemenu”>
  15. <li class=“current” dataid=“1”></li>
  16. <li dataid=“2”></li>
  17. </ul>
  18. <div id=“changenr”></div>
复制代码
快速发帖

  1. <a href="forum.php?mod=misc&action=nav" οnclick="showWindow('nav', this.href, 'get', 0);">发布新话题</a>
复制代码
常用词汇

  1. select 选择
  2. count 总数
  3. table 表
  4. where 条件
  5. result 结果
  6. perpage 每页
  7. curpage 当前页
  8. update 更新
  9. delete 删除
  10. insert 写入
  11. dateline 日期
  12. time 时间
  13. echo 输出 <?php echo '123'; ?>
  14. multi 分页函数
  15. if 如果
  16. else 否则
  17. elseif
  18. start 起始
  19. limit 限制 limit 10
  20. DESC 倒序
  21. ASC 正序
复制代码

————————————————
原文链接:
https://blog.csdn.net/mwb310/article/details/53420178
wuwaila发表于 2019-10-7 22:11:35
提示: 作者被禁止或删除 内容自动屏蔽
ujunuxeutt发表于 2019-10-7 22:40:03
  • Admin : test
こはね发表于 2019-10-8 01:37:41
ujunuxeutt 发表于 2019-10-7 22:40
Amoxicillin 500 Mg Amoxicillin 500 Mg zhl.maku.aoebbs.net.vas.gv http://mewkid.net/buy-xalanta/

I'm surprised to see you. How did you know we changed domain names?
uyuvolaqoru发表于 2019-10-12 08:04:54
???? Posted at 2019-10-8 01:37
I'm surprised to see you. How did you know we changed domain names?

omihusu发表于 2019-10-12 08:13:04
???? Posted at 2019-10-8 01:37
I'm surprised to see you. How did you know we changed domain names?

跳转到