简体   繁体   English

如何以编程方式更改分页配置文件中的total_rows

[英]How to programatically change the total_rows in the pagination config file

Im wondering if it is possible to change the total_rows dynamically in the pagination config file as the total_rows may be not be the same for all the queries. 我想知道是否有可能在分页配置文件中动态更改total_rows 因为对于所有查询来说total_rows可能都不相同。 Here is my code: 这是我的代码:

$config['base_url'] = current_url();
$config['total_rows'] = 200; //I need to change dynamically
$config['per_page'] = 20;
$config['full_tag_open'] = '<div class="pagination pagination-small pagination-centered">';
$config['full_tag_close'] = '</div>';
$config['next_link'] = '&gt;';
$config['prev_link'] = '&lt;';
$config['first_link'] = '';
$config['last_link'] = '';

Thanks 谢谢

You can try something like this : 您可以尝试这样的事情:

$count = $this->db->count_all_results( 'table_name' );

$total_rows = 4;
  if ( $count > $total_rows ) {
    $config['base_url'] = current_url();
    $config['total_rows'] = $count; //I need to change dynamically
    $config['per_page'] = 20;
    $config['full_tag_open'] = '<div class="pagination pagination-small pagination-centered">';
    $config['full_tag_close'] = '</div>';
    $config['next_link'] = '&gt;';
    $config['prev_link'] = '&lt;';
    $config['first_link'] = '';
    $config['last_link'] = '';  
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM