【问题标题】:codeigniter pagination link is not working when i select the link当我选择链接时,codeigniter 分页链接不起作用
【发布时间】:2014-09-14 08:41:17
【问题描述】:

请求你帮助分页链接。 在我的数据库中,我有 3 条记录,我想每页显示一条记录。当我选择分页链接的下一个数字时,没有获取数据。事情是,当我单击分页链接的第 2 个数字时,echo var_dump() 显示结果为空,并且我没有得到 echo $data-> 的任何值电子邮件。但是当我第一次搜索时,我能够显示单个记录,问题只是分页的下一个链接那么可能是什么错误?我无法得到答案,我不确定会发生什么,所以我在下面发布我的代码,请仔细阅读并帮助我。 请求你帮助我。

**HERE STARTS MY CONTROLLER**

 public function users($limit=1,$offset = 0)
{
$this->load->helper('url');
$data = array();
$look = $this->input->post('look');
$age = $this->input->post('age');
$age_from = $this->input->post('age_from');
$age_to = $this->input->post('age_to');
$se_ct = $this->input->post('sect');
$subsect = $this->input->post('subsect');
$coun_try = $this->input->post('country');
$sta_te = $this->input->post('state');
$ci_ty = $this->input->post('city');
$qualification = $this->input->post('qualification');
$results = $this->searchresultss->login($look, $age, $age_to, $age_from, $se_ct, $subsect, $coun_try, $sta_te, $ci_ty, $qualification);
$this->load->helper('url');
$config = array();
$config['base_url'] = base_url().'searchresult/users';
$config['total_rows'] = count($results);
$config['per_page'] = $limit;
$this->load->library('pagination', $config);
$data['pagination_links'] = $this->pagination->create_links();
$data['results'] = array_slice($results, $offset, $limit);
 $this->load->view('searchresult', $data);
$this->load->view('includes/khelp');
$this->load->view('includes/kfooter');


**HERE STARTS MY MODEL PAGE**

     Class Searchresultss extends CI_Model
            {

            public function login($look, $age, $age_to, $age_from, $se_ct, $subsect, $coun_try, $sta_te, $ci_ty, $qualification)
            {

                    return $this->db->query("SELECT *
                    FROM users
                    WHERE   gender = '$look'
                    And status='1'")->result();

             }

            }


**HERE START MY VIEW PAGE**
echo var_dump($_POST);
if (empty($results)) {
 echo 'Results set is empty';
        } else 
        {
        foreach ($results as $data) {
                echo $data->email.'<br />';
            }

        }
        echo $pagination_links;

【问题讨论】:

  • 点击分页链接的第 2 号时会丢失帖子变量
  • 好吧,我是新人,你能简单解释一下吗..varun 我会很感激的
  • 您在查询中使用了后置变量 $look。当您单击 2 号链接时。 $look 变量中没有任何值
  • 好的..所以我需要做些什么改变varun请不要介意你能告诉我更正吗
  • 有2个解决方案可用。 1. 将 post 变量移动到会话变量并在创建查询时使用会话变量。 2.在URL中添加所有post变量。

标签: php codeigniter pagination


【解决方案1】:

问题在于分页链接不包含 POST 变量(以及通过 GET 请求超链接的事实)。 我建议您在 $_GET 和 $_POST 上执行 var_dump() ,问题会变得更加明显。

一个可能的解决方案是将 post 变量包含为 url 参数。比如

$config['base_url'] = base_url().'searchresult/users/look_param/age_param/etcetc';

但是您需要添加功能来处理上述问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 2014-11-20
    • 1970-01-01
    • 2014-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多