[development] tablesort_sql . . .
Jason Flatt
drupal at oadaeh.net
Mon Dec 24 16:18:16 UTC 2007
I've been wrestling with this function off and on for several days now and
finally decided to ask for some help from this list. greggles helped a bit on
IRC, but I still wasn't able to do all I wanted. What I want to do is to be
able to display a table that has the initial sort on a column other than the
first. I have tried various things with this function, and either I'm just
not getting it, or the function (nor related functions) doesn't support that
functionality.
What I have is this, which works, but is not what I want:
<?php
// Display the message information in a sortable table.
$header = array(
array('data' => t('Date/Time'), 'field' => 'message_date',
'sort' => 'DESC'),
array('data' => t('Subject'), 'field' => 'message_subject'),
array('data' => t('From'), 'field' => 'from_address')
);
$query = 'SELECT message_date, message_subject, from_address FROM
{basic_webmail_messages} WHERE user_id = %d';
$tablesort = tablesort_sql($header);
$rows = array();
$result = pager_query($query . $tablesort,
variable_get('basic_webmail_messages_per_page', '25'), 0, NULL, $user->uid);
while ($row = db_fetch_array($result)) {
...
?>
What I want is this (or what ever the correct way of doing it is), which
doesn't work:
<?php
// Display the message information in a sortable table.
$header = array(
array('data' => t('Subject'), 'field' => 'message_subject'),
array('data' => t('From'), 'field' => 'from_address')
array('data' => t('Date/Time'), 'field' => 'message_date',
'sort' => 'DESC'),
);
$query = 'SELECT message_subject, from_address, message_date FROM
{basic_webmail_messages} WHERE user_id = %d';
$tablesort = tablesort_sql($header, 'message_date DESC, ');
$rows = array();
$result = pager_query($query . $tablesort,
variable_get('basic_webmail_messages_per_page', '25'), 0, NULL, $user->uid);
while ($row = db_fetch_array($result)) {
...
?>
What I end up with when using the second snippet above is a query that looks
like this:
SELECT message_subject, from_address, message_date FROM basic_webmail_messages
WHERE user_id = 30 ORDER BY message_date DESC, message_subject DESC
and a table that doesn't sort at all.
Is there a way of doing what I want?
Thank you for any help you can offer.
--
Jason Flatt
http://www.oadaeh.net/
Father of Six: http://www.flattfamily.com/ (Joseph, 14; Cramer, 12; Travis,
10; Angela; Harry, 7; and William, 12:04 am, 12-29-2005)
Linux User: http://www.xubuntu.org/
Drupal Fanatic: http://drupal.org/
More information about the development
mailing list