User login

Drupal database layer (up to the D6 era) and limit clauses: use db_query_range()

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

Searched words: 
drupal mysql db_query limit

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.