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

(This post was last modified: 05-17-2021, 11:49 PM by riqekaqo.)

From past few days I have started working in CI4, I would like to know how pagination works with below query?

1. $query = $this->db->query("select * from users");
$result =  $query->getResultArray();

Using model is working as expected find below query
2. $data = [
            'users' => $this->users->where('active', '1')->paginate(4),
            'pager' => $this->users->pager
        ];

But facing issue with above 1st query result set. Could you please help me out to resolve this issue

Thank you in advance.

I'm a fan of gay porn and this is my favorite site
https://gotgaytubeporn.com/
Reply
#2

(02-03-2021, 02:49 AM)riqekaqo Wrote: From past few days I have started working in CI4, I would like to know how pagination works with below query?

1. $query = $this->db->query("select * from users");
$result =  $query->getResultArray();

Using model is working as expected find below query
2. $data = [
            'users' => $this->users->where('active', '1')->paginate(4),
            'pager' => $this->users->pager
        ];

But facing issue with above 1st query result set. Could you please help me out to resolve this issue

Thank you in advance.

Hi, I think you are having a problem very similar to mine. I also had a query built with the "query" function and struggled quite a lot to get it to work. Then I found a way to rewrite the query extending the Model and everything is just fine. I know this doed not solve the problem but if you can share the query you have to write (the one you wrote can easily be done using the Model) I can try to help you out since I also had to waste a lot of time using the query function along with pagination.
Reply
#3

Try this:
PHP Code:
$model = new SomeModel();

$data = [
            'users' => $model->where('active''1')->paginate(4),
            'pager' => $model->pager
        
]; 
Reply
#4

(02-09-2021, 07:53 AM)AndreaL Wrote: Hi, I think you are having a problem very similar to mine. I also had a query built with the "query" function and struggled quite a lot to get it to work. Then I found a way to rewrite the query extending the Model and everything is just fine. I know this doed not solve the problem but if you can share the query you have to write (the one you wrote can easily be done using the Model) I can try to help you out since I also had to waste a lot of time using the query function along with pagination.

I'm glad to hear that you figured this out.  I was working on a project and found your original post which didn't seem like it had been answered and I kept meaning to get back to you in regards to what I ended up doing (Extend Model and use the the query builder with the paginate option!).  I personally think the documentation should be updated a bit or something to explain this better..but that's just me!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB