Welcome Guest, Not a member yet? Register   Sign In
Datamapper pagination: total rows and current rows
#1

[eluser]Wazzu[/eluser]
Hi all, I-m having troubles using DMZ pagination.
I have 15 records and want to show 10 records per page.
As you can see below, I make use of $o=>count to check how many records I have found
Later I want to narrow that search so I can get just some of them, so I call $o->limit(10, $page)->get() but in this case, all my previous wheres and likes are gone.

How can I get the total number of rows within the filter and then paginate them using the same query parameters?

Code:
// User list
$o = new User();
$o->where('group_id', '3');
        
// filter
if($this->input->post('search')) {
    foreach($this->input->post('searchkey') as $key=>$value) {
        $o->like($key, $value);
        $searchkey[$key] = $value;
    }
}

// users found
$num = $o->count();

// If users found
if($num) {
    // Pagination
    $o->limit(10, $page)->get();
    $this->load->library('pagination');
    $this->pagination->initialize($config);
}
#2

[eluser]jeffpeck[/eluser]
Maybe they can be stored in session data?
#3

[eluser]Wazzu[/eluser]
There must be some way to reuse previous $o->where and $o->like.
I can use another local variable, without using session space, but Im sure there is something I could use :-(
#4

[eluser]Wazzu[/eluser]
The bad news: you can't reuse your query after a count or a get call

The good news: you can get a clone and use it for count, so your real object keeps all clausules.

Found the answer at: http://ellislab.com/forums/viewthread/136039/P250/ (check from post #253)

Documentation here: http://www.overzealous.com/dmz/pages/clonecopy.html




Theme © iAndrew 2016 - Forum software by © MyBB