[Zope-DB] dynamic order by clause in sql query

Mike Guerrero mguerrero@tachyon.net
Thu, 7 Feb 2002 13:58:43 -0800


Hello,

I have a sql method that I have define as follows :
select field1, field2, field3 from mytab order by field1.

I have a dtml-doc to display the results. The results display in a typical
html table.  I would like to have the table headers be links to re-sort the
same page by whatever field the user chooses. Currrently, I have 3 sql
methods (to sort explicitly on field1 or field2 or field3) and 3 separate
dtml doc to display the results.

I would like to cut this down to 1 sql method for the sql and 1 dtml doc for
the results.

I have defined a new sql method (sql_1) as follows (the arg is
order_by_col):
select field1, field2, field3 from mytab order by <dtml-sqlvar order_by_col
type="int">
I can test this out fine.  If I pass a 1,2, or 3 my results will be sorted
by the appropriate column.

I can't get the dtml doc (doc1) to work with my new sql method.  How can I
create the links to call the same page that I'm on.  I have the following
for doc1:

<table>
  <th><a href="mypath/sql1/1/doc1">field1</a></th>    (note: I want click
and sort on col 1)
  <th>field2</th>
  <th>field3</th>
...
</table>

I haven't had success getting this to work.

Is there a better way to do this?

Thanks.

Mike