Search code examples
phpmysqllithium

Lithium - How to get the number of fetched rows?


In Lithium, after fetching all rows of a given Model like this:

$users = Users::all();

how can I know how many rows were returned? I'm using the MySQL connector.

Thank you!


Solution

  • If you just want the count

    $usersCount = Users::count();
    

    If you want the count of your collection

    $users = Users::all();
    $usersCount = count($users->data())
    

    I think you can also do

    $usersCount = $users->count();
    

    I'm aware the above two methods will return the same result.
    The second method is in case he calls Model::find() instead of Model::all().