Welcome Guest, Not a member yet? Register   Sign In
pagination problem
#1

[eluser]Asinox[/eluser]
Hi, i hav problems with pagination, my problem is whit count all results...

which is the best way to count all results for pagination?
#2

[eluser]Bramme[/eluser]
You really should look into the user guide more often :p

$this->db->count_all('my_table') is easily the most easy function to get all the rows from my_table...
#3

[eluser]Asinox[/eluser]
ejej ejejej ejejej very nice comment Tongue jeje but im always there , but the problem is that for pagination we need num,offset and i hav always problem with this...
#4

[eluser]hvalente13[/eluser]
Hi Asinox,

You could do it like this in your model:

Code:
function get_results($param,$limit=15,$offset){
     $this->db->select('*');
     $this->db->where('field',$param);
     $data['num_rows'] = $this->db->count_all_results('mytable');
     $data['result'] = $this->db->get('mytable',$limit,$offset);

     return $data;
}

and retrieve the data in the controller like this:
Code:
function index(){
     $config['per_page'] = '10';
     $all_result_set = $this->my_model->get_results('keyword',$config['per_page'],$this->uri->segment(3));
     $config['total_rows']=$all_result_set['num_rows'];
     $data['results']=$all_result_set['result'];

     // the rest of pagination settings
}

Hope this helps.

Good luck
#5

[eluser]Asinox[/eluser]
Thanks hvalente13 Smile ur way is very nice for me Smile

Thanks Smile
#6

[eluser]Asinox[/eluser]
ok, i hav some problem with pagination... i see the numbers of navigation links, but when i clicked the number navigator links i get the 404 no found pages....
#7

[eluser]Michael Wales[/eluser]
Pagination doesn't just automatically happen.

The pagination library simply helps you in generating those links at the bottom - which pass an offset to whatever method you tell it to. You then use that offset to show the "next page"
#8

[eluser]Asinox[/eluser]
i fixed... just in the router i added the url/:num

thanks Smile
#9

[eluser]jeffersonrpn[/eluser]
I have a question about this. When I want to use pagination on entire table result I use "count_all_results()" and "get()" functions. And it works fine. But when I have a complex query with JOINs and WHERE clauses, how I should count the result?

P.S. Sorry if my english is poor.
#10

[eluser]Bramme[/eluser]
num_rows() ?

Code:
$query = $this->db->query("SELECT * FROM table JOIN blahdieblah WHERE stuff");
$all_results = $query->num_rows();




Theme © iAndrew 2016 - Forum software by © MyBB