1
votes

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 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.

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.

Here is my controller.

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

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.

**Here is my view page**

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

//Error is when i select next numeric link of pagination record is not being fetched from database getting output as emty result in my view page.so request you to help me in solving the issue and more warning message is  missiing argument 2 for Searchresult::users() , and more errror message is undefined variable offset .
2
you have to pass for pagination $config['base_url'] with all parameters, which you passing while loading page, paste your pagination code as well. - Reena Shirale
$config['base_url'] = base_url().'searchresult/users/$look/$age/$age_to/$age_from/$se_ct/$subsect/$coun_try/$sta_te/$ci_ty/$qualification'; - manoj kumar
//The URI you submitted has disallowed characters. is the errror what iam getting - manoj kumar
need to set offset & Limit as well, Please check codeigniter pagination,paste your controller,model function. - Reena Shirale
problem still sustain Reena - manoj kumar

2 Answers

0
votes

First, there is no need to pass 100 parameters that you don't even use, get rid of those.

Now to the code.

function login($look, $page = 0, $offset = 1){
    $query = $this->db->get_where('users', array('gender' => $look, 'status' => '1'), $limit, $offset);
    return $query;
}

that should work.

0
votes

first pagination configuration :-

   $config['base_url'] = base_url() . 'controller_name/function_name/';
   $config['per_page'] = 20;    //lets say 20 record per page 
   $config['total_rows'] = $total_rows;
   $this->pagination->initialize($config);

get data from the database depending upon pagination configuration

  $start = $this->uri->segment(3, 0);
  $queryNum = $this->db->get('table_name');
    $num = $queryNum->num_rows();
    if ($num > 0) {
        $config['total_rows'] = $num; //reset total rows

        $this->db->limit($config['per_page'], $start);
        $queryNum1 = $this->db->get('table_name');
        foreach ($queryNum1->result() as $rows) {
            $tmp[] = $rows; //holds the query result data
        }
     }
    $data1['pagination'] = $this->pagination->create_links();