O'Reilly logo

Drupal 7 First Look by Mark Noble

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dynamic query extensions

The DBTNG layer provides developers with the ability to extend the query functionality for Select statements. There are two query extensions that are shipped with core. These allow you to easily page records and enable users to easily sort data displayed in tables. We will look at each in detail next.

Paging records

In Drupal 6, paging was done using a pager_query. In Drupal 7, the easiest way to add pagination to your query is using the PagerDefault query extender. This takes care of automatically loading the current page from the page request to properly display the results for the current page. The extender can be added to the query by calling the extend method:

<?php $query = db_select('node', 'n'); $query->addField('n', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required