webCOMAND

query::limit()

Sets the LIMIT clause to limit the number of query results.

To "unset" an existing limit, so there is no limit, use limit(0).

Prototype

limit(int $count): query
limit(int $offset, int $count): query
limit(array $offset_count): query

Parameters

The following parameters may be passed in any of the forms listed above.

  • count - Restrict the number of results to count items.  Set to zero (0) to "unset" an existing limit, so there will no longer be a limit.
  • offset - Exclude/skip rows before offset.
  • offset_count - array containing [$count] or [$offset, $count].

Return

The updated query object is returned.  This is handy for chaining additional methods.

Example

// limit results to the second "page"
$page = 2;
$items_per_page = 10;
$offset = $page * $items_per_page;
$query->limit($offset, $items_per_page);

// same as above, but passed as array
$query->limit([$offset, $items_per_page]);

// limit to the first 12 items
$query->limit(12);

Related

limit_again()