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();
3条答案
按热度按时间70gysomp1#
在codeigniter3.16中,我需要产品的总数&page=1个产品
codeigniter文档
3j86kqsm2#
问题是执行querybuilder方法
get
两次,但在第二次查询中没有定义任何内容对你来说,我更喜欢
SQL_CALC_FOUND_ROWS
选项n1bvdmb63#