简体   繁体   English

Codeigniter分页链接不起作用

[英]Codeigniter pagination link is not working

I'm new to CI so guys request to help me in displaying result for pagination link. 我是CI的新手,所以有人要求帮助我显示分页链接的结果。 In database, I have 3 records I'm displaying a single record for each page. 在数据库中,我有3条记录,每页显示一条记录。 Problem is in my pagination link when i select next numeric link of pagination, result is not being displayed. 问题是当我选择下一个分页数字链接时,我的分页链接中没有显示结果。

Thing is that that when I click on number 2 of pagination link output shows results is empty and I am not getting any values for echo $data->email.Below is my controller,model,view. 问题是,当我单击分页链接输出的数字2时,显示结果为空,并且没有得到echo $ data-> email.E的任何值。以下是我的控制器,模型,视图。

I have tried many ways but no use i even completely follwed google even though no use. 我已经尝试了很多方法,但是没有用,即使没有用,我也完全放弃了Google。 I think the problem is when the page is loading to get second record from database when the pagination link is selected post values are no more passing to model page so might be the problem. 我认为问题是当选择分页链接时页面正在加载以从数据库获取第二条记录时,帖子值不再传递给模型页面,所以可能是问题所在。

Here is my controller. 这是我的控制器。

public function users($limit=1,$offset){
 $this->load->helper('url');
 $this->load->view('includes/kheader');
 $this->load->view('includes/kmenu');
 $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);
   //for base_url()
    $this->load->helper('url');
   //Pagination Config
    $config = array();
   // $config['base_url'] = base_url().'searchresult/users';
   $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();
     //Reducing the number of results for the view
    /** NOTE: This is not the most efficient way **/
    //echo $data;
    $data['results'] = array_slice($results,$offset,$limit);
$this->load->view('searchresult', $data);

Here is my model page 这是我的模特页面

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();
            }

I'm not able to get an answer through google too But one record is being displayed when the page load's problem is when I select pagination link of next numeric link it is not working. 我也无法通过谷歌获得答案,但是当页面加载的问题是当我选择下一个数字链接的分页链接不起作用时,将显示一条记录。 Pagination script is not working properly i think it is related to offset. 分页脚本无法正常工作,我认为它与偏移量有关。 So what might be the error I'm not sure so I am posting my code below please go through it and and help me. 所以我不确定是什么错误,所以我在下面发布了我的代码,请仔细阅读并为我提供帮助。

//Error is when I select next numeric link of pagination ,record is not being fetched from database I am getting output as empty result in my view page.so request you to help me in solving the issue and more warning message is missing argument 2 for Searchresult::users() , and more error message is undefined variable offset . //错误是当我选择下一个分页的数字链接时,未从数据库中获取记录时,我的视图页面中的输出为空结果。因此请您帮助我解决问题,并且缺少更多警告消息,参数2对于Searchresult :: users(),更多错误消息是undefined variable offset。

Here is view page 这是查看页面

if (empty($results)) {
    echo 'Results set is empty';
} else {
foreach ($results as $data) {
        echo $data->email.'<br />';
    }
}
echo $pagination_links;

Has I am new to ci iam looking for a ci developer who can sought my problem if there are any mistakes please don't mind. 我是ci iam的新手吗,如果有任何错误,请不要介意寻找可以解决我问题的ci开发人员。

Consider this example: 考虑以下示例:

        // Pagination Library
        $this->load->library('pagination'); 

        $Row_Per_Page = $this->rpp; // or direct assign 10 as int


        $Page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

        // Only for Query String ?page=2&parm=val&parm2=val2
        $this->pagination->suffix = ! empty($QS) ? "?" . $QS : "";


        // Configuration Settings
        $config['base_url'] = base_url("cpanel/invoices");
        $config['total_rows'] = $this->invoice->invoices_count($QS);
        $config['per_page'] = $Row_Per_Page;
        $config["uri_segment"] = 3;
        $config['first_link'] = 'First';
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['last_link'] = 'Last';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
        $config['next_link'] = '&raquo;';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['prev_link']  = '&laquo;';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a href="javascript:;">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';

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

        // Pass variables to query 
        // $config["per_page"] -> Row Per Page
        // $Page -> Holds the Starting Limit from URI Segment
        $this->settings['Invoices'] = $this->invoice->get_invoice_list( $config["per_page"], $Page, $this->input->server('QUERY_STRING') ); 
        $this->settings['Pagination_Link'] = $this->pagination->create_links();




        $this->load->view('cpanel/invoice_lists', $this->settings );

Read the comments between the codes for better understand. 阅读代码之间的注释以更好地理解。 Hope this help you. 希望这对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM