您现在的位置是:首页 > cms教程 > Discuz教程Discuz教程

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

紫山2025-07-01Discuz教程已有人查阅

导读首先在最底层source\class\table写入底层安全调用文件例如:table_common_friendlink.php然后前台source\module\portal调用查询文件:portal_index.php

首先在最底层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.ebingou.cn/ $value[url]" target="_blank">$value[name]</a>
<!--{/loop}-->
</div>
</section>

本文标签:

很赞哦! ()

相关源码

  • (自适应)物流运输快递仓储货运网站模板免费下载基于PbootCMS内核开发的物流运输行业专用模板,深度适配仓储货运企业的业务展示需求。前端采用响应式布局,自动适配手机端访问,后台数据实时同步更新,帮助企业高效展示运输网络、仓储设施、服务流程等核心业务模块。查看源码
  • (自适应)HTML5响应式双语绿色物流运输快递货运pbootcms源码本款基于PbootCMS开发的网站模板为物流运输、快递货运行业设计,采用HTML5技术构建,支持简繁字体切换。模板设计充分考虑了货运物流行业的特点,可专业展示运输服务、物流网络和业务优势等内容。查看源码
  • (PC+WAP)蓝色不锈钢簧线金属制品营销型pbootcms网站模板本模板基于PbootCMS内核开发,为不锈钢及金属制品企业量身打造。采用响应式设计,适配PC与移动设备,提供统一后台管理体验,数据实时同步更新。查看源码
  • (自适应响应式)英文外贸汽车零配件五金机械网站模板为汽车零部件制造商与五金机械出口企业打造的响应式网站模板,内置多语言切换功能,支持产品参数表、OEM能力展示等外贸场景需求。通过结构化数据展示帮助海外买家快速理解产品规格。查看源码
  • (自适应)包装机贴标机设备网站源码免费下载基于PbootCMS内核开发的响应式企业模板,为包装机械、贴标设备等工业领域打造,通过数字化展示提升企业专业形象。查看源码
  • pbootcms模板(PC+WAP)微信小程序开发公司网站本模板为微信小程序开发代理、软件开发公司等企业设计,基于PbootCMS内核开发,支持PC+WAP双端响应式布局,数据实时同步,适用于多行业快速建站。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐