zoukankan      html  css  js  c++  java
  • discuz 万能SQL查询调用语句写法

    首先在最底层sourceclass able写入底层安全调用文件例如:table_common_friendlink.php 

    代码:

    <?php
    
    /**
     *      [Discuz!] (C)2001-2099 Comsenz Inc.
     *      This is NOT a freeware, use is subject to license terms
     *
     *      $Id: table_common_friendlink.php 27449 2012-02-01 05:32:35Z zhangguosheng $
     */
    
    if(!defined('IN_DISCUZ')) {
        exit('Access Denied');
    }
    
    class table_common_friendlink extends discuz_table
    {
        public function __construct() {
    
            $this->_table = 'common_friendlink';
            $this->_pk    = 'id';
    
            parent::__construct();
        }
    
        public function fetch_all_by_displayorder($type = '')
        {
            $args = array($this->_table);
            if($type) {
                $sql = 'WHERE (`type` & %s > 0)';
                $args[] = $type;
            }
            return DB::fetch_all("SELECT * FROM %t $sql ORDER BY displayorder", $args, $this->_pk);
        }
        
        public function fetch_all_by_sql($where, $order = '', $start = 0, $limit = 0, $count = 0, $alias = '') {
            $where = $where && !is_array($where) ? " WHERE $where" : '';
            if(is_array($order)) {
                $order = '';
            }
            if($count) {
                return DB::result_first('SELECT count(*) FROM '.DB::table($this->_table).'  %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order));
            }
            return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order));
        }
    
    }
    
    ?>

    然后前台sourcemoduleportal调用查询文件:portal_index.php

    代码:

    <?php
    
    if(!defined('IN_DISCUZ')) {
        exit('Access Denied');
    }
    include_once libfile('function/portalcp'); //此处可不用。
    
    //discuz 万能SQL查询调用语句写法
    $wheresqla = " type=2 "; 
    $ordera = " ORDER BY id ASC ";   
    $linksa = C::t('common_friendlink') -> fetch_all_by_sql($wheresqla, $ordera, 0, 20);
    
      
    include_once template('diy:portal/index');
    ?>

    模板处templatedefaultportal调用文件:portalcp_index.htm

    代码:

        <section class="wp d_friendlinks mtw">
            <div class="d_friendlinksbg"></div>
            <div class="d_friendlinksa">
            <!--{loop $linksa $value}-->
            <a href="http://www.juhutang.com/ $value[url]" target="_blank">$value[name]</a>
            <!--{/loop}-->
            </div>
        </section>
  • 相关阅读:
    GDOI 2019 退役记
    SHOI2019 游记
    【WC2014】紫荆花之恋
    PKUWC 2019 & NOIWC2019 比赛总结 Formal Version
    WC 2019 颓废记
    VDUVyRLYJC
    Git学习
    DOM学习笔记
    python基础---->AJAX的学习
    python基础---->进程、线程及相关等
  • 原文地址:https://www.cnblogs.com/php411161555/p/3878056.html
Copyright © 2011-2022 走看看