function chado_pager_query
2.x tripal_core.chado_query.api.inc | chado_pager_query($query, $args, $limit, $element, $count_query = '') |
3.x tripal_chado.query.api.inc | chado_pager_query($query, |
1.x tripal_core_chado.api.inc | chado_pager_query($query, $limit, $element, $count_query) |
Use this function instead of pager_query() when selecting a subset of records from a Chado table.
@returns A database query result resource or FALSE if the query was not executed correctly
Parameters
$query: The SQL statement to execute, this is followed by a variable number of args used as substitution values in the SQL statement.
$limit: The number of query results to display per page.
$element: An optional integer to distinguish between multiple pagers on one page.
$count_query: An SQL query used to count matching records.
Related topics
2 calls to chado_pager_query()
- tripal_core_chado_select in tripal_core/
api/ tripal_core_chado.api.inc - Provides a generic routine for selecting data from a Chado table
- tripal_pub_get_search_results in tripal_pub/
includes/ pub_search.inc
File
- tripal_core/
api/ tripal_core_chado.api.inc, line 2357 - The Tripal Core API
Code
function chado_pager_query($query, $limit, $element, $count_query) {
// The following code is almost an exact duplicate of the
// Drupal pager_query function. However, substitions have
// been made to call chado_query rather than db_query
global $pager_page_array, $pager_total, $pager_total_items;
$page = isset($_GET['page']) ? $_GET['page'] : '';
// get the SQL query arguments that get substituted into modifiers later.
$args = func_get_args();
$args = array_slice($args, 4);
// Alternative syntax for '...'
if (isset($args[0]) && is_array($args[0])) {
$args = $args[0];
}
// Construct a count query if none was given.
if (!isset($count_query)) {
$count_query = preg_replace(array('/SELECT.*?FROM /As', '/ORDER BY .*/'), array('SELECT COUNT(*) FROM ', ''), $query);
}
// Convert comma-separated $page to an array, used by other functions.
$pager_page_array = explode(',', $page);
// We calculate the total of pages as ceil(items / limit).
$pager_total_items[$element] = db_result(chado_query($count_query, $args));
$pager_total[$element] = ceil($pager_total_items[$element] / $limit);
$pager_page_array[$element] = max(0, min((int) $pager_page_array[$element], ((int) $pager_total[$element]) - 1));
return chado_query_range($query, $args, $pager_page_array[$element] * $limit, $limit);
}