tablesort_sql

Definition

tablesort_sql($header, $before = '')
includes/tablesort.inc, line 50

Description

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

Namesort iconDescription
Database abstraction layerAllow the use of different database servers using the same code base.

Code

<?php
function tablesort_sql($header, $before = '') {
  $ts = tablesort_init($header);
  if ($ts['sql']) {
    $sql = db_escape_string($ts['sql']);
    $sort = strtoupper(db_escape_string($ts['sort']));
    return " ORDER BY $before $sql $sort";
  }
}
?>
 
 

Drupal is a registered trademark of Dries Buytaert.