2013-11-26 59 views
1

我想知道是否可以在分頁配置文件中動態更改total_rows ,因爲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'] = ''; 

感謝

+0

我認爲唯一的辦法是在你的控制器重新聲明你的配置設置的特定情況下,當它不是200. – Jeemusu

回答

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

謝謝,但可以使它更加靈活。我的意思是我正在使用PDO,並且我可能需要的行數可能不總是特定表中的行總數。一個例子是,從學生中選擇*名稱,其名稱如'%Lea%'。謝謝 – Lomse

+0

但是你爲什麼要動態地改變total_rows。 我的意思是,per_page已經限制了將顯示多少行。 對不起,但我只是想知道爲什麼你需要這個。 – Chiribuc

相關問題