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>
  • 相关阅读:
    MMA7660
    使用外设需要做的事情
    BH1750
    English
    2016年学习计划
    博客园
    TIM
    USART
    swift与oc的混合编程
    SVN工具如何创建分支和合并分支的
  • 原文地址:https://www.cnblogs.com/php411161555/p/3878056.html
Copyright © 2011-2022 走看看