### pageBySql
**动态构建某一页select sql并执行**
**参数**
\* 1.$sql:传入的基本select语句
\* 2.$param:构造sql所需参数
\* 返回: Array 二维数组.第一维是所有记录,第二维是某条记录的字段数组
~~~
function pageBySql($sql) {
//构建group by
$groupBy = $this->groupBy;
$countPos=strpos ( $sql, "@" );
//拼装搜索条件
$sql = $this->createQuery ( $sql, $this->searchArr );
if(empty($countPos)){
$countPos=strpos ( $sql, "from" );
}else{
$sql=str_replace ( "@", "", $sql );
}
if (isset ( $groupBy ) && $groupBy != "" && $groupBy != "id") {
$groupBy = " group By $groupBy ";
$countsql = "select 0 " . substr ( $sql, $countPos );
//$countsql = $this->createQuery ( $countsql, $this->searchArr );
$countsql = "select count(0) as num from ( " . $countsql . " " . $groupBy . " ) as t";
} else {
//构造获取记录数sql
$countsql = "select count(0) as num " . substr ( $sql, $countPos );
//$countsql = $this->createQuery ( $countsql, $this->searchArr ); //TODO;待优化,无需执行两次createQuery
}
//print($countsql);
$this->count = $this->queryCount ( $countsql );
//拼装聚合函数
$sql .= $groupBy;
//构建排序信息
if(!empty($this->sort)){
$asc = $this->asc ? "DESC" : "ASC";
//echo $this->asc;
$sql .= " order by " . $this->sort . " " . $asc;
}
$this->listSql=$sql;
//print($sql);
//构建获取记录数
$sql .= " limit " . $this->start . "," . $this->pageSize;
//echo $sql;
return $this->_db->getArray ( $sql );
}
~~~
- 架构
- 基础框架文档
- base/action(C层基类)
- protected 类定义
- __construct构造函数
- c_list
- c_index
- c_page
- c_pageJson
- c_listJson
- c_getByAjax
- c_getCountByName
- c_toAdd
- c_add
- c_init
- c_edit
- c_deletes
- c_ajaxdeletes
- c_saveBatch
- c_checkRepeat
- getDatadicts
- showDatadicts
- getDataNameByCode
- assign
- display
- view
- assignFunc
- model/base(M层基类)
- protected类定义(model)
- __construct
- find
- get_table_fields
- findAll
- findSql
- create
- delete
- findBy
- updateField
- query
- findCount
- update
- filterFunc
- filterField
- filterWithoutField
- filterCustom
- createBatch
- pageBySql
- listBySql
- pageBySqlId
- deletes
- 事务控制
- 获取对象数组
- addBatch_d
- add_d
- edit_d
- isRepeat
- 列表组件文档
- 基础表格
- 数据获取
- 表格数据显示
- 常用控制参数
- 表格右键扩展
- 表格扩展按钮
- 快速搜索
- 高级搜索(自定义视图)
- 表格注册事件
- 主从表格
- 可编辑表格
- 模块开发
- 开发案例
- 开发准则