# Loading Stats events from the database

Just like when [loading SystemLogEvents from the database](https://cherrycake.tin.cat/guide/log-guide/loading-systemlog-events-from-the-database), you can use the provided [StatsEvents](https://cherrycake.tin.cat/reference/core-classes/statsevents) class to retrieve and work with lists of [StatsEvent](https://cherrycake.tin.cat/reference/core-classes/statsevent) objects.

For example, let's load the last fifty `StatsEventHomeView` objects from our [earlier example](https://cherrycake.tin.cat/guide/stats-guide), using what we learned in the [Item lists](https://cherrycake.tin.cat/guide/items-guide/item-lists) section of the [Items guide](https://cherrycake.tin.cat/guide/items-guide):

```php
$statsEventItems = new \Cherrycake\Stats\StatsEvents([
    "p" => [
        "type" => "CherrycakeApp\StatsEventHomeView",
        "limit" => 50
    ]
]);

foreach ($statsEventItems as $statsEvent) {
    echo
        $e->Locale->formatTimestamp($statsEvent->timestamp).
        ": ".$statsEvent->typeDescription.
        ": ".$statsEvent->count.
				"\n";
}
```

As you can see, the [StatsEvents](https://cherrycake.tin.cat/reference/core-classes/statsevents/statsevents-methods#fillfromparameters) class accepts some additional keys on top of the usual [Items::fillFromParameters](https://cherrycake.tin.cat/reference/core-classes/items/items-methods#fillfromparameters) keys:

* **`type`** Retrieves only [StatsEvent](https://cherrycake.tin.cat/reference/core-classes/statsevent) objects of this class name. Must include the full namespace route to the class.
* **`fromTimestamp`** Retrieves [StatsEvent](https://cherrycake.tin.cat/reference/core-classes/statsevent) objects triggered after this timestamp.
* **`toTimestamp`** Retrieves [StatsEvent](https://cherrycake.tin.cat/reference/core-classes/statsevent) objects triggered up to this timestamp.

```
5/21/20: Home view: 90
5/22/20: Home view: 1
```

{% hint style="success" %}
See examples of loading StatsEvent object from the database in the [Triggering a stats event ](https://documentation-examples.cherrycake.io/example/statsGuideTriggeringEvent)and [Events with additional dimensions](https://documentation-examples.cherrycake.io/example/statsGuideAdditionalDimensions) examples.
{% endhint %}
