> For the complete documentation index, see [llms.txt](https://cherrycake.tin.cat/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cherrycake.tin.cat/version-1.x-beta/guide/stats-guide/loading-stats-events-from-the-database.md).

# Loading Stats events from the database

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

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

```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](/version-1.x-beta/reference/core-classes/statsevents/statsevents-methods.md#fillfromparameters) class accepts some additional keys on top of the usual [Items::fillFromParameters](/version-1.x-beta/reference/core-classes/items/items-methods.md#fillfromparameters) keys:

* **`type`** Retrieves only [StatsEvent](/version-1.x-beta/reference/core-classes/statsevent.md) objects of this class name. Must include the full namespace route to the class.
* **`fromTimestamp`** Retrieves [StatsEvent](/version-1.x-beta/reference/core-classes/statsevent.md) objects triggered after this timestamp.
* **`toTimestamp`** Retrieves [StatsEvent](/version-1.x-beta/reference/core-classes/statsevent.md) 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 %}
