Hi,

This is a bit unclear - any sorting is either based on some combination of
values, be they columns, bits of columns, static values or random values,
and so can be expressed as an Order BY clause.

For example, I have a report that allows the user to say in which order the
columns should be sorted, and create an order by clause (in 'C') from their
selections.

Are you able to clarify things a bit further?

Quentin

-----Original Message-----
From: Michael Todd Glazier [mailto:[EMAIL PROTECTED]]
Sent: Friday, 23 March 2001 8:31 a.m.
To: [EMAIL PROTECTED]
Subject: Dynamic Custom Sort Orders


hey all! I'm developing a CGI app for access to a mysql table. I want 
to offer users the ability to arbitrarily sort the results. That is, 
given the following table:

letter
-----
A
B
C

I want to sort the results as B,C,A , C,A,B, and such. I need to do 
this from a single select statement so I can use the LIMIT parameter 
to keep state and page through the results.

The best solution I've come up with so far is to dynamically build an 
IF statement like the following. Assume the requested order is C, A, B

SELECT letter, IF(letter='C',1,IF(letter='A',2,IF(letter='B',3,4))) 
as MYORDER FROM alpha ORDER BY MYORDER

This works, but it seems a tad clumsy. Also, the real table and sort 
order uses and combines multiple columns, so it gets really hairy. 
How to use formulas to affect sort order in the ORDER BY clause isn't 
clear to me (other than RAND()), so I'm wondering if a cleaner 
solution lies there.

Any thoughts would  be appreciated

Peace,

Michael Todd

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail
<[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

The information contained in this email is privileged and confidential
and intended for the addressee only. If you are not the intended 
recipient, you are asked to respect that confidentiality and not 
disclose, copy or make use of its contents. If received in error 
you are asked to destroy this email and contact the sender immediately. 
Your assistance is appreciated.

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to