discuz 万能SQL查询调用语句写法
2014-07-30 14:56
543 查看
首先在最底层source\class\table写入底层安全调用文件例如:table_common_friendlink.php
代码:
然后前台source\module\portal调用查询文件:portal_index.php
代码:
模板处template\default\portal调用文件:portalcp_index.htm
代码:
代码:
<?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>
相关文章推荐
- 三表左连接查询的sql语句写法
- sql 语句对于两个时间段的查询写法
- 查询所有订单的最新信息的SQL语句的写法 DISTINCT配合count和group by一起完成
- Sql中查询含有中括号的where语句写法
- 三表左连接查询的sql语句写法
- 关于oracle中PL/SQL语句,即存储过程的写法和调用。
- ACTION 关联表之间查询语句 SQL语句写法
- Java程序和Oracle数据库调用相同的SQL查询语句,结果却不同
- java jdbc调用oracle的函数或过程返回SQL语句查询的结果集
- access 查询sql语句中日期型的写法
- 多表查询语句写法、数据库数字如何转化为汉子、Sql语句拼接
- 查询最大值SQL语句写法
- ACTION 中 单表查询语句 SQL写法
- 几种常见复合sql查询语句的linq写法[继续补充中]
- 在SQL语句中查询多条记录并把多条记录同一字段的值连接成一个字符并返回的写法
- SQL中统计数据的查询语句写法
- sql语句查询优化总结,建议及写法技巧(汇总)
- Oracle clob类型的字段作为查询条件的sql语句写法
- SQL查询时间段的语句写法
- ADO方式,VC调用Execute执行INSERT INTO插入变量SQL语句的写法