【问题标题】:next page or page 2 reset the searched value in pagination下一页或第 2 页重置分页中的搜索值
【发布时间】:2018-05-25 02:07:40
【问题描述】:

我是这里的新用户。我正在尝试为 CRM 系统创建一个带有搜索过滤器的简单分页。有五个过滤器选项用于搜索和显示记录。我想要每页 100 条记录,并且我的过滤器选项在第一页上运行良好。问题是当我单击下一页或第二页以显示搜索数据的下 100 条记录时,它正在重置所有过滤器值并显示 100 条记录,我无需选择任何过滤器值即可获得这些记录。我正在寻找这个问题的解决方案,以便我可以根据给定的过滤器值获取下一页。

下面我给出了我的控制器和视图页面的分页部分,

Controller page

if (!isset($_GET['page']) or !is_numeric($_GET['page'])) {
          $page = 0;
        } else {
          $page = (int)$_GET['page']; 
        } 
$customerslist = array();    
            $customers = $db->query("select cu.email, cu.notinterested, cu.version, cu.autoresponder, cu.customer_support, cu.verified, cu.verified_date, cu.customer_id, cu.customer_name, cu.address, cu.telephone_no, cu.email, cu.person_incharge, cu.designation, ct.city_name, st.state_name, emp.username from customers  as cu left join state as st on st.id = cu.state left join city as ct on ct.id = cu.city    left join tbllogin as emp on emp.employee_id = cu.customer_support
             where cu.customer_name!='' and cu.customer_support>0 and cu.company_id='".$cid."' ".$cont." ".$order_by." limit ".$page.",100");

            foreach($customers->fetchAll() as $cl) {
                $customerslist[] = $cl;
            }  



view page

        <?php
        $nextt = $page + 100;
        if ($sno > 100)
        echo '<a href="?controller=customers&action=index&cid='.$cid.'&page='.$nextt.'"><b>Next<b></a>';

        $prev = $page - 100;
        ?>&nbsp;&nbsp;&nbsp;<?php
        if ($prev >= 0)
        echo '<a href="?controller=customers&action=index&cid='.$cid.'&page='.$prev.'"><b>Previous<b></a>';
        ?>

【问题讨论】:

  • 您需要将所有搜索参数传递给分页链接
  • 能否详细解释一下?
  • 在搜索中给我你的 GET 参数列表
  • $customer_name = $_POST['customer_name']; $state_id = $_POST['state_id']; $customer_action = $_POST['customer_action']; $customer_support = $_POST['customer_support']; $versions = $_POST['version_id']; $test = $_POST['test']; $email = $_POST['emailoption'];

标签: php


【解决方案1】:

首先始终使用GET方法进行搜索表单提交:

$customer_name = $_POST['customer_name']; 
$state_id = $_POST['state_id']; 
$customer_action = $_POST['customer_action']; 
$customer_support = $_POST['customer_support']; 
$versions = $_POST['version_id']; 
$test = $_POST['test']; 
$email = $_POST['emailoption']; 
$cid = $_POST['cid']; 

$pagination_str = '';
if($customer_name) $pagination_str .= '&customer_name='.$customer_name;
if($state_id) $pagination_str .= '&state_id='.$state_id;
if($customer_action) $pagination_str .= '&customer_action='.$customer_action;
if($customer_support) $pagination_str .= '&customer_support='.$customer_support;
if($versions) $pagination_str .= '&versions='.$versions;
if($test) $pagination_str .= '&test='.$test;
if($email) $pagination_str .= '&email='.$email;
if($cid) $pagination_str .= '&cid='.$cid;

echo '<a href="?controller=customers&action=index?page='.$nextt.$pagination_str.'"><b>Next<b></a>';

【讨论】:

  • 另外,您需要为上一页链接添加相同的内容
  • 您好,当我点击下一页时使用此代码显示“错误页面”结果,查询中有什么需要做的吗?
  • 我刚刚给出了解释,如何将参数与分页字符串一起使用。您必须根据您的要求修改代码
  • 查询限制有什么关系吗?
  • 糟糕,这是错误页面。好像出了点问题。
猜你喜欢
  • 2012-06-18
  • 2023-03-31
  • 1970-01-01
  • 2019-10-03
  • 1970-01-01
  • 1970-01-01
  • 2018-01-21
  • 2019-01-02
  • 2021-03-23
相关资源
最近更新 更多