您现在的位置是:首页 > 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源码下载本网站模板基于PbootCMS内核精心开发,为机械设备与工业产品制造企业量身打造。设计充分考量行业特性,突出产品展示与技术实力呈现查看源码
  • 帝国CMS7.5漫画网站模板带手机端源码免费下载本模板为漫画内容平台设计开发,采用帝国CMS7.5内核构建,深度优化漫画作品展示结构与章节管理模式。前端采用响应式布局设计,适配各类漫画阅读场景,提供作品分类、连载追踪、热度排行等垂直领域功能模块。查看源码
  • (自适应响应式)pbootcms食品零食店日化用品网站源码下载基于PbootCMS内核开发的响应式模板,为食品零食、日化用品等行业量身定制。该模板通过可视化设计展现产品特色,帮助企业快速搭建专业官网查看源码
  • pbootcms(自适应)SEO优化排名服务公司网站模板核心定位为SEO排名服务商打造的营销型网站框架,集成PbootCMS开源系统的高效管理能力与SEO最佳实践方案,助力企业快速建立专业的技术服务形象。查看源码
  • (自适应)html5导航目录索引工具类网站源码下载本模板基于PbootCMS开发,为站长导航、网址导航类网站设计。采用HTML5+CSS3技术构建,适配PC端和移动端,提供流畅的浏览体验。适用于个人站长、资源导航平台等场景查看源码
  • (自适应响应式)HTML5中小学早教教育机构类网站pbootcms模板下载基于PbootCMS内核开发的响应式模板,为早教中心、培训学校等教育机构打造,提供从技术架构到视觉呈现的全套网站建设方案。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐