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

时间:2013-11-26 00:24:39

标签: codeigniter pagination

我想知道是否可以在分页配置文件中动态更改total_rows ,因为所有查询的total_rows可能不同。这是我的代码:

$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'] = '';

由于

1 个答案:

答案 0 :(得分:1)

您可以尝试这样的事情:

$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'] = '';  
  }