tablesort_sql

Versions
4.6 – 6
tablesort_sql($header, $before = '')

Create an SQL sort clause.

This function produces the ORDER BY clause to insert in your SQL queries, assuring that the returned database table rows match the sort order chosen by the user.

Parameters

$header An array of column headers in the format described in theme_table().

$before An SQL string to insert after ORDER BY and before the table sorting code. Useful for sorting by important attributes like "sticky" first.

Return value

An SQL string to append to the end of a query.

Related topics

▾ 15 functions call tablesort_sql()

comment_admin_overview in modules/comment/comment.admin.inc
Form builder; Builds the comment overview form for the admin.
dblog_overview in modules/dblog/dblog.admin.inc
Menu callback; displays a listing of log messages.
dblog_top in modules/dblog/dblog.admin.inc
Menu callback; generic function to display a page of the most frequent dblog events of a specified type.
forum_get_topics in modules/forum/forum.module
path_admin_overview in modules/path/path.admin.inc
Return a listing of all defined URL aliases. When filter key passed, perform a standard search on the given key, and return the list of matching URL aliases.
poll_votes in modules/poll/poll.pages.inc
Callback for the 'votes' tab for polls you can see other votes on
statistics_node_tracker in modules/statistics/statistics.pages.inc
statistics_recent_hits in modules/statistics/statistics.admin.inc
Menu callback; presents the "recent hits" page.
statistics_top_pages in modules/statistics/statistics.admin.inc
Menu callback; presents the "top pages" page.
statistics_top_referrers in modules/statistics/statistics.admin.inc
Menu callback; presents the "referrer" page.
statistics_top_visitors in modules/statistics/statistics.admin.inc
Menu callback; presents the "top visitors" page.
statistics_user_tracker in modules/statistics/statistics.pages.inc
system_actions_manage in modules/system/system.module
Menu callback. Display an overview of available and configured actions.
user_admin_access in modules/user/user.admin.inc
Menu callback: list all access rules
user_admin_account in modules/user/user.admin.inc
Form builder; User administration page.

Code

includes/tablesort.inc, line 38

<?php
function tablesort_sql($header, $before = '') {
  $ts = tablesort_init($header);
  if ($ts['sql']) {
    // Based on code from db_escape_table(), but this can also contain a dot.
    $field = preg_replace('/[^A-Za-z0-9_.]+/', '', $ts['sql']);

    // Sort order can only be ASC or DESC.
    $sort = drupal_strtoupper($ts['sort']);
    $sort = in_array($sort, array('ASC', 'DESC')) ? $sort : '';

    return " ORDER BY $before $field $sort";
  }
}
?>
Login or register to post comments
 
 

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.