1

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 .
Magic-Mouse
  • 603
  • 10
  • 21

2 Answers2

0

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.

Magic-Mouse
  • 603
  • 10
  • 21
  • iam using those parameters ..thing is i shorted my query thats its – manoj kumar Sep 15 '14 at 06:31
  • does print_r($this->db->get('users')); return anything ? – Magic-Mouse Sep 15 '14 at 06:43
  • yes if i change my model to public function login($look, $age, $age_to, $age_from, $se_ct, $subsect, $coun_try, $sta_te, $ci_ty, $qualification) { $query = $this->db->get("users"); if ($query->num_rows() > 0) { foreach ($query->result() as $row) { $data[] = $row; } return $data; } } gettting same proble what i posted in my question – manoj kumar Sep 15 '14 at 06:48
  • It looks like you need to sanitize your URL, not as i thought, need to fix your database, but i looked the wrong place because you didn't inform us in your question that you did remove something from your query. Remember to inform if you leave something out that might cause the problem next time :) – Magic-Mouse Sep 15 '14 at 06:55
  • Oh I am extremely sorry ...How to solve the issue where i might be wrong – manoj kumar Sep 15 '14 at 06:57
  • Add this to your config file $config['permitted_uri_chars'] = 'a-z 0-9~%.:&_\-'; – Magic-Mouse Sep 15 '14 at 07:32
  • And read this: http://stackoverflow.com/questions/19297433/codeigniter-redirect-the-uri-you-submitted-has-disallowed-characters and https://www.google.com/search?q=The+URI+you+submitted+has+disallowed&oq=The+URI+you+submitted+has+disallowed – Magic-Mouse Sep 15 '14 at 07:33
0

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();
Rajeev Ranjan
  • 4,152
  • 3
  • 28
  • 41