【发布时间】:2018-06-28 13:05:30
【问题描述】:
Codeigniter 单个查询有限制和无限制?
我正在尝试使用单个查询对数据库进行分页:我需要具有 where 条件且没有限制的记录总数,数据通过相同查询获得限制。
$this->db->select( '*' );
if ( ! empty( $id ) ) {
$this->db->where( "id", $id );
}
if ( ! empty( $to ) ) {
$this->db->where( "to", $to );
}
if ( $is_deleted !="" ) {
$this->db->where( "is_deleted", $is_deleted );
}
if ( ! empty( $from ) ) {
$this->db->where( "from", $from );
}
if ( ! empty( $priority ) ) {
$this->db->where( "priority", $priority );
}
$this->db->order_by( $orderby, $order );
$total_records = $this->db->get( $this->Table )->num_rows();
if ( $page < 1 ) {
$page = 1;
}
if ( $pagesize < 1 ) {
$pagesize = 1;
}
$offset = ( $page - 1 ) * $pagesize;
$rows = $this->db->get( $this->Table, $pagesize, $offset )->result_array();
【问题讨论】:
标签: php mysql codeigniter