db_query_range

includes/database.pgsql.inc, line 183

Versions
4.6 – 6
db_query_range($query)
7
db_query_range($query, $args, $from = 0, $count = 0, $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.

$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

▾ 23 functions call db_query_range()

aggregator_block in modules/aggregator.module
Implementation of hook_block().
aggregator_page_categories in modules/aggregator.module
Menu callback; displays all the categories used by the aggregator.
aggregator_page_sources in modules/aggregator.module
Menu callback; displays all the feeds used by the aggregator.
archive_page in modules/archive.module
Menu callback; lists all nodes posted on a given date.
blogapi_blogger_get_recent_posts in modules/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.module
Implementation of hook_block().
blog_feed_last in modules/blog.module
Displays an RSS feed containing recent blog entries of all users.
blog_feed_user in modules/blog.module
Displays an RSS feed containing recent blog entries of a given user.
comment_block in modules/comment.module
Implementation of hook_block().
forum_block in modules/forum.module
Implementation of hook_block().
forum_get_forums in modules/forum.module
Returns a list of all forums for a given taxonomy id
hook_update_index in developer/hooks/core.php
Update Drupal's full-text index for this module.
node_feed in modules/node.module
A generic function for generating RSS feeds from a set of nodes.
node_update_index in modules/node.module
Implementation of hook_update_index().
pager_query in includes/pager.inc
Perform a paged database query.
sess_read in includes/session.inc
statistics_title_list in modules/statistics.module
Returns all time or today top or last viewed node(s).
taxonomy_select_nodes in modules/taxonomy.module
Finds all nodes that match selected taxonomy conditions.
update_85 in database/updates.inc
user_block in modules/user.module
Implementation of hook_block().
user_load in modules/user.module
Fetch a user object.
_comment_update_node_statistics in modules/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.module
Finds the first unread node for a given forum.

Code

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

  $query = db_prefix_tables($query);
  if (count(func_get_args()) > 3) {
    // Check for array (alternative syntax).
    if (is_array($args[1])) {
      $args = array_merge(array($query), $args[1]);
    }
    $args = array_map('db_escape_string', $args);
    $args[0] = $query;
    $query = call_user_func_array('sprintf', $args);
  }
  $query .= ' LIMIT '. (int)$count .' OFFSET '. (int)$from;
  return _db_query($query);
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.