Php 使用表单搜索/筛选分页

Php 使用表单搜索/筛选分页,php,mysql,codeigniter,pagination,codeigniter-pagination,Php,Mysql,Codeigniter,Pagination,Codeigniter Pagination,我是codeigniter框架的新手,我正在尝试使用搜索过滤器进行分页 我遇到过这样的答案(虽然没有答案),也没有勾选答案,所以我不确定这是不是正确的方法,而且很困惑 我所拥有的是,默认情况下,页面将显示使用分页的表的所有结果 现在我陷入了困境,弄得一团糟,所以如果有一些明显的错误,请原谅我 因此,我在这里试图做的是,当用户在下拉框中选择一个值并提交(比如客户a)时,我只希望列Customer中包含Customer a的行 然而,在提交之后,我得到了所有的结果,更糟糕的是,在没有页眉和页脚的纯文

我是codeigniter框架的新手,我正在尝试使用搜索过滤器进行分页

我遇到过这样的答案(虽然没有答案),也没有勾选答案,所以我不确定这是不是正确的方法,而且很困惑

我所拥有的是,默认情况下,页面将显示使用分页的表的所有结果

现在我陷入了困境,弄得一团糟,所以如果有一些明显的错误,请原谅我

因此,我在这里试图做的是,当用户在下拉框中选择一个值并提交(比如客户a)时,我只希望列
Customer
中包含
Customer a
的行

然而,在提交之后,我得到了所有的结果,更糟糕的是,在没有页眉和页脚的纯文本中(单独的视图)。我理解这是因为我没有给他们打电话,但它仍然没有显示那些只有
客户A
的人

我们一直在试图找到一个简单的解决方案,在表单提交之后,paginate查询将根据从表单获取的值执行,并显示所选行。除了这两个链接外,似乎找不到其他链接,因此我不确定是否采用了正确的过滤方式

查看

<form method="POST" action='<?php echo base_url("index.php/Home/load_lot_table")?>' class="form-inline">
     <select id="cust_drop_down" name="cust_drop_down" class="form-control input-mini">
         <option value="all">All</option>
         <option value="custA">Customer A</option>
         <option value="custB">Customer B</option>
     </select>

     <input type="submit" class="btn btn-primary purple_button" value="Search">
</form>
型号

public function record_count()
{
    return $this->db->count_all('disp_dummy');
}

public function fetch_lots($limit, $start, $search = null)
{
    $this->db->limit($limit, $start);

    if($search != null && $search['customer'] != 'all')
    {
        $this->db->where('customer', $search['customer']);
    }

    $query = $this->db->get('disp_dummy');

    if($query->num_rows() > 0)
    {
        foreach($query->result() as $row)
        {
            $data[] = $row;
        }
        return $data;
    }
    else
    {
        return false;
    }
}

您需要对代码进行一些更改:

首先,使用GET request提交您的搜索,因为您无法在第二页中获取用于分页的已发布参数:

查看:

<form method="GET" action='<?php echo base_url("index.php/Home/load_lot_table")?>' class="form-inline">
     <select id="cust_drop_down" name="cust_drop_down" class="form-control input-mini">
         <option value="all">All</option>
         <option value="custA">Customer A</option>
         <option value="custB">Customer B</option>
     </select>

     <input type="submit" class="btn btn-primary purple_button" value="Search">
</form>
在您的模型中,在搜索功能中进行如下修改:

型号

 public function load_lot_table() // Main pagination function
{

    if($this->input->get('cust_drop_down'))
    {
        $search = array(
        'customer' => $this->input->get('cust_drop_down')
        );
    }
    else
    {
        $search = array(
        'customer' => 'all',
        'stage' => 'all',
        'lot_status' => 'all'
        );
    }
    $config = array();
    $config['base_url'] = base_url()."index.php/Home/on_hold_lot";
    $config['total_rows'] = $this->home_model->fetch_lots($search)->num_rows();
    $config['per_page'] = 10;
    $config['uri_segment'] = 3;
    $config['next_link'] = 'Next';
    $config['prev_link'] = 'Previous';

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

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $results = $this->home_model->fetch_lots($search, $config['per_page'], $page)->result_array();

    $data['disp_rows'] = $results;
    $data['links'] = $this->pagination->create_links();

    return $this->load->view('home/lot_disposition', $data);
}
public function fetch_lots($search = null, $limit = null, $start = 0)
{
   if($limit != null){
       $this->db->limit($limit, $start);
    }


    if($search != null && $search['customer'] != 'all')
    {
        $this->db->where('customer', $search['customer']);
    }

    $query = $this->db->get('disp_dummy');

    if($query->num_rows() > 0)
    {
       return $query;
    }
    else
    {
        return false;
    }
}

嗯,好的,我按照你的建议做了,仍然可以显示,但是我仍然用纯文本,但是有过滤器。我觉得我返回视图的方式有问题。我怎样才能显示像我的
on\u hold\u lot
函数这样的视图?哦,我只需要将表单操作更改为显示视图的函数。谢谢你的简单解释!但是
next
链接或第2页不起作用,它将重置值并显示
all
的原始记录,但仅显示下一个10/next页。
public function fetch_lots($search = null, $limit = null, $start = 0)
{
   if($limit != null){
       $this->db->limit($limit, $start);
    }


    if($search != null && $search['customer'] != 'all')
    {
        $this->db->where('customer', $search['customer']);
    }

    $query = $this->db->get('disp_dummy');

    if($query->num_rows() > 0)
    {
       return $query;
    }
    else
    {
        return false;
    }
}