db_query_range

  1. drupal
    1. 4.7 database.mysqli.inc
    2. 4.7
    3. 4.7 database.mysql.inc
    4. 5 database.mysqli.inc
    5. 5
    6. 5 database.mysql.inc
    7. 6 database.mysqli.inc
    8. 6 database.mysql.inc
    9. 6 database.pgsql.inc
    10. 7 database.inc
Versions
4.7 – 6 db_query_range($query)
7 db_query_range($query, $from, $count, array $args = array(), array $options = array())

Runs a limited-range query in the active database.

Use this as a substitute for db_query() when a subset of the query is to be returned. User-supplied arguments to the query should be passed in as separate parameters so that they can be properly escaped to avoid SQL injection attacks.

Parameters

$query A string containing an SQL query.

... A variable number of arguments which are substituted into the query using printf() syntax. Instead of a variable number of query arguments, you may also pass a single array containing the query arguments. Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose in '') and %%.

NOTE: using this syntax will cast NULL and FALSE values to decimal 0, and TRUE values to decimal 1.

$from The first result row to return.

$count The maximum number of result rows to return.

Return value

A database query result resource, or FALSE if the query was not executed correctly.

Related topics

▾ 31 functions call db_query_range()

aggregator_block in modules/aggregator/aggregator.module
Implementation of hook_block().
aggregator_page_categories in modules/aggregator/aggregator.module
Menu callback; displays all the categories used by the aggregator.
aggregator_page_rss in modules/aggregator/aggregator.module
Menu callback; generate an RSS 0.92 feed of aggregator items or categories.
aggregator_page_sources in modules/aggregator/aggregator.module
Menu callback; displays all the feeds used by the aggregator.
blogapi_blogger_get_recent_posts in modules/blogapi/blogapi.module
Blogging API callback. Returns the latest few postings in a user's blog. $bodies TRUE <a href="http://movabletype.org/docs/mtmanual_programmatic.html#item_mt%2EgetRecentPostTitles"> returns a bandwidth-friendly list</a>.
blog_block in modules/blog/blog.module
Implementation of hook_block().
blog_feed_last in modules/blog/blog.module
Displays an RSS feed containing recent blog entries of all users.
blog_feed_user in modules/blog/blog.module
Displays an RSS feed containing recent blog entries of a given user.
comment_get_recent in modules/comment/comment.module
Find a number of recent comments. This is done in two steps. 1. Find the n (specified by $number) nodes that have the most recent comments. This is done by querying node_comment_statistics which has an index on last_comment_timestamp, and is thus a…
drupal_is_denied in includes/bootstrap.inc
Perform an access check for a given mask and rule type. Rules are usually created via admin/user/rules page.
forum_block in modules/forum/forum.module
Implementation of hook_block().
forum_get_forums in modules/forum/forum.module
Returns a list of all forums for a given taxonomy id
forum_submit in modules/forum/forum.module
Implementation of hook_submit().
hook_update_index in developer/hooks/core.php
Update Drupal's full-text index for this module.
node_feed in modules/node/node.module
A generic function for generating RSS feeds from a set of nodes.
node_update_index in modules/node/node.module
Implementation of hook_update_index().
pager_query in includes/pager.inc
Perform a paged database query.
profile_admin_settings_autocomplete in modules/profile/profile.module
Retrieve a pipe delimited string of autocomplete suggestions for profile categories
profile_autocomplete in modules/profile/profile.module
Callback to allow autocomplete of profile text fields.
statistics_title_list in modules/statistics/statistics.module
Returns all time or today top or last viewed node(s).
system_update_159 in modules/system/system.install
Retrieve data out of the old_revisions table and put into new revision system.
system_update_172 in modules/system/system.install
system_update_178 in modules/system/system.install
Update base paths for relative URLs in node and comment content.
system_update_179 in modules/system/system.install
Update base paths for relative URLs in custom blocks, profiles and various variables.
taxonomy_autocomplete in modules/taxonomy/taxonomy.module
Helper function for autocompletion
taxonomy_select_nodes in modules/taxonomy/taxonomy.module
Finds all nodes that match selected taxonomy conditions.
update_fix_system_table in ./update.php
user_autocomplete in modules/user/user.module
Retrieve a pipe delimited string of autocomplete suggestions for existing users
user_block in modules/user/user.module
Implementation of hook_block().
_comment_update_node_statistics in modules/comment/comment.module
Updates the comment statistics for a given node. This should be called any time a comment is added, deleted, or updated.
_forum_new in modules/forum/forum.module
Finds the first unread node for a given forum.

Code

includes/database.pgsql.inc, line 278

<?php
function db_query_range($query) {
  $args = func_get_args();
  $count = array_pop($args);
  $from = array_pop($args);
  array_shift($args);

  $query = db_prefix_tables($query);
  if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax
    $args = $args[0];
  }
  _db_query_callback($args, TRUE);
  $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
  $query .= ' LIMIT ' . (int) $count . ' OFFSET ' . (int) $from;
  return _db_query($query);
}
?>