Since limiting queries to a certain range depends on the underlying database engine, we also have the queryRange() method on our database connection service, which we can use to write queries that include ranges:
$result = $database->queryRange("SELECT * FROM {players}", 0, 10);
In this example, we query for all the players and limit the result set to the first ten records (from 0 to 10). So, with this method, the placeholder value array is the fourth parameter after $from and $count.
Alternatively, using the SELECT query builder, we have a method on the SelectInterface whereby we can specify a range. So, in that format, the preceding query would look like this:
$result = $database->select('players', 'p')
->fields('p')
->range(0, 10)
->execute();
As you can see, we have the range() method, which takes those arguments and limits the query.
No comments:
Post a Comment