Home ›
Drupal database layer (up to the D6 era) and limit clauses: use db_query_range()Drupal database layer (up to the D6 era) and limit clauses: use db_query_range()
Submitted by Benjamin Melançon on April 1, 2009 - 1:41pm
Searched words:
drupal mysql db_query limit
Variables passed in first, and then a start and as stop value for indexing (zero and ten, here).
<?php
$result = db_query_range(db_rewrite_sql($sql), $type, $status, 0, 10);
?>
An example from node module's search integration, node_update_index(), makes it clearer:
<?php
$limit = (int)variable_get('search_cron_limit', 100);
// ...
$result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit);
?>
Resolution
More like this
- Reviving FOAF (scavanging Walkah's Drupal 4.6-era foaf module)
- When naming projects that will spawn a database, be mindful of 16 character limit
- Must use -> fields() method in select statements in Drupal 7 database layer (DBTNG)
- Poor performance of Drupal 5 internationalized site due to lack of database table indexes?
- Be sure to register templates moved to module layer, and moving functions from template.php to module


Comments
Post new comment