简体   繁体   中英

Codeigniter pagination link is not working

I'm new to CI so guys request to help me in displaying result for pagination link. In database, I have 3 records I'm displaying a single record for each page. 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.

I have tried many ways but no use i even completely follwed google even though no use. 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 .

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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