Search code examples
codeigniter-4

Codeigniter 4 how to show if records where a certain name appears in more than X rows


I would like to ask how do I show if a particular name appears for more than X rows in my table.

For mySQL query : SELECT COUNT(*) FROM table WHERE fieldname = 2;

For CI4, is it the same like this : $users = $userModel->asObject('count')->where('fieldname', '2')->findAll();

If not, can anyone tell me what is the right query for CI4? Thanks in advance guys!


Solution

  • Ok, I managed to solve it by using

    $users = $model->where('fieldname', '2')
                    ->countAllResults();
    

    Hope this helps someone out there.