<p>By default, Craft sets a limit of 100. Set it to null: <code>limit(null)</code>.</p>

CC BY-SA 3.0
2016-07-27T03:49:28.360Z
2016-07-27T03:49:28.360Z
awcross
<p>Craft imposes a default limit of 100 for element queries. To disable this you need to specify a limit of <code>null</code>.</p>

<pre><code>$criteria-&gt;limit = null;
</code></pre>

CC BY-SA 3.0
2016-07-27T07:16:02.857Z
`$criteria->limit = -1` also works :) `null` is more clear, though.
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2016-07-27T03:50:04.143Z
2016-07-27T06:31:59.620Z
2016-07-27T06:31:59.620Z
Ben Fleming
<p>I am trying to export data from a database to a csv file, I am using the code below to retrieve the data from the DB, but it only returns 100 rows, how can I fix that?</p>

<pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;section = 'educators';
$query = craft()-&gt;elements-&gt;buildElementsQuery($criteria);
$query-&gt;order('title asc');
$queryResults = $query-&gt;queryAll();
$educators = EntryModel::populateModels($queryResults);

foreach ($educators as $educator) {
   //Write to file
}
</code></pre>

CC BY-SA 3.0
2016-07-27T07:13:47.767Z
Your code could be simplified by adding an array as a second parameter to `getCriteria()`, i.e. `$criteria = craft()->elements->getCriteria(ElementType::Entry, ['section' => 'educators', 'order' => 'title asc', 'limit' => null]);` and then just `$educators = $criteria->find();` – in other words; you don't need the calls to `buildElementsQuery()` and `queryAll()` in this particular instance, and `$criteria->find()` will actually return an array of EntryModels so there's no need to manually populate those.
Mats Mikkel Rummelhoff
<database><queries>
Query only returning 100 records at a time?
# Query only returning 100 records at a time?

(Asked by: username_0 on 2016-07-27)

I am trying to export data from a database to a csv file, I am using the code below to retrieve the data from the DB, but it only returns 100 rows, how can I fix that?
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = 'educators';
$query = craft()->elements->buildElementsQuery($criteria);
$query->order('title asc');
$queryResults = $query->queryAll();
$educators = EntryModel::populateModels($queryResults);

foreach ($educators as $educator) {
   //Write to file
}

**Tags:** database, queries
> **Comments:**
> **username_1**: Your code could be simplified by adding an array as a second parameter to `getCriteria()`, i.e. `$criteria = craft()->elements->getCriteria(ElementType::Entry, ['section' => 'educators', 'order' => 'title asc', 'limit' => null]);` and then just `$educators = $criteria->find();` – in other words; you don't need the calls to `buildElementsQuery()` and `queryAll()` in this particular instance, and `$criteria->find()` will actually return an array of EntryModels so there's no need to manually populate those.  

---

## 2 answers

### Answer by username_3 on 2016-07-27. Score: 10 | Accepted answer

Craft imposes a default limit of 100 for element queries. To disable this you need to specify a limit of null.
$criteria->limit = null;

> **Comments:**
> **username_1**: `$criteria->limit = -1` also works :) `null` is more clear, though.  

---

### Answer by username_2 on 2016-07-27. Score: 5

By default, Craft sets a limit of 100. Set it to null: `limit(null)`.


---

