[Zope] sort based on a variable

Passin, Tom tpassin@mitretek.org
Mon, 17 Mar 2003 17:33:18 -0500


I like to have the database to the sorting whenever possible.  You can
change your sql statement to something like

select col1,co2,col3 from tab1 order=3D'<dtml-var t_sort_order>'

Or, a little more compact using entity notation,

select col1,co2,col3 from tab1 order=3D'&dtml-t_sort_order;'

If you want to sort on more than one column, just create the right
string for t_sort_order.

Cheers,

Tom P

[Michael Guerrero]

I have a table tab1 with 3 columns col1,co2,col3.

I've defined a sql method 'get_list' as 'select col1,co2,col3 from tab1.

In a dtml method (view_list)I want call get_list and sort on any of the
three columns.  I know I can do the following:

<dtml-in get_list sort=3D"col2">
   display stuff here
</dtml-in>

I'm passing the sort order column to view_list using -->
view_list?sort_order=3Dcol2

I get no error but incorrect results when I try to do the following in
view_list:
<dtml-call "REQUEST.set('t_sort_order',sort_order)">
<dtml-in sql_list_rma sort=3Dt_sort_order>

I also tried putting various combinations of single and double quotes
around t_sort_order' without any luck.

I can display t_sort_order, so I know it's getting the proper value.  It
just doesn't evaluate correctly.  I think it has something with
double-quotes needing to surround the sort filename.

I really don't want to create 3 sql methods
(get_list_by_col1,get_list_by_col2,get_list_by_col3).

I'd appreciate any help.

Thanks.

Mike Guerrero