Php 从codeingiter中的输入类型文本设置$per_页面

Php 从codeingiter中的输入类型文本设置$per_页面,php,html,codeigniter,Php,Html,Codeigniter,大家好,我有以下问题:我已经在codeigniter分页类的帮助下设置了分页,但我想做更多的事情: 我希望用户在输入框中输入一个值。。。然后自动将$per_page设置为该值: 这是我的密码: public function index($offset = NULL, $limit = NULL) { $this->load->library('pagination'); $offset = $this->uri->segment

大家好,我有以下问题:我已经在codeigniter分页类的帮助下设置了分页,但我想做更多的事情:

我希望用户在输入框中输入一个值。。。然后自动将
$per_page
设置为该值:

这是我的密码:

public function index($offset = NULL, $limit = NULL)
    {
        $this->load->library('pagination');

        $offset = $this->uri->segment(3);
        $total = $this->db->count_all('posts');

        $per_page = 5;      

        $config['base_url'] = base_url().'welcome/index';
        $config['total_rows'] = $total;
        $config['uri_segment'] = 3;
        $config['per_page'] = $per_page;

        $this->pagination->initialize($config); 

        $data['pagination'] = $this->pagination->create_links();
        $data['posts'] = $this->Model_cats->get_pagination_field($config['per_page'], $offset);
等等

分页工作非常好

这是html:

<div id="pagination">

    <?php  echo $pagination;?> 
    <input type="text" id="set_pagination">
    <input type="submit" id="submit_pagination">

</div>

好的,我怎样才能提交一个数字,比如说3,并显示每页3篇文章


有什么想法吗<代码>$per_page=$this->input->post。。。。有些东西..

首先将您的每页更改为

$per_page = 3;
并向您的模型发送$per_页面,包括偏移量

$data['posts'] = $this->Model_cats->get_pagination_field($config['per_page'], $offset,$per_page);
在你的模型上写下限制为

$this->db->limit($perpage,$offset);
就这样……希望它对您有所帮助

按照步骤进行操作

1) save the text box value in DB.

2) In DB there will be a single row containing value of per_page. all time this value will be updated.

3) when you are using pagination class pick up that value from DB. 

希望这对你有用。任何比这更好的想法都值得赞赏。

一种方法是将值发布到函数中

<div id="pagination">
   <?php echo form_open("controller/function"); ?>
    <?php  echo $pagination;?> 
    <input type="text" id="set_pagination" name="set_pagination">
    <input type="submit" id="submit_pagination">
   <?php echo form_close(); ?>
</div>

然后将值存储在DB(或)Session中。

我添加了@PaulHarbuz Use Session或将值存储在DB中。然后在所有页面中引用
$per_page = $this->input->post('set_pagination');