discuz 万能SQL查询调用语句写法

首先在最底层source\class\table写入底层安全调用文件例如: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));
    }

}

?>

 

然后前台source\module\portal调用查询文件: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');
?>

 

模板处template\default\portal调用文件: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>

 

转载于:https://www.cnblogs.com/php411161555/p/3878056.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值