Tiago Alves
Tiago Alves

Reputation: 1321

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!

Upvotes: 1

Views: 320

Answers (1)

anon
anon

Reputation:

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().

Upvotes: 7

Related Questions