[Zope] Sorting rows from a database in reverse order
Ben Glazer
glazer@scicomp.com
Wed, 22 Sep 1999 15:43:42 -0500
I have a question about sorting rows returned by an SQL query. I'm running
Zope 2.0 with a Z MySQL DB connection.
display_news is a Z SQL Method that contains the following query:
SELECT DATE_FORMAT(date, '%b %d, %Y') as date,
headline,
url
FROM news
I use display_news in the following DTML fragment:
<dtml-in display_news sort=date>
<a href="<dtml-var url>"><dtml-var headline></a><br>
<dtml-var date>
<br><br>
</dtml-in>
When I view the page containing the above DTML, the news headlines are
displayed such that the oldest news is at the top of the page and the newest
is at the bottom. Now, I know that I can use "ORDER BY date DESC" in the
SQL query and remove the "sort=date" dtml-in parameter to accomplish the
task, but I'm not sure that it's really the most efficient way, nor that it
will always work.
So here are the questions whose answers will settle the matter for me:
1. Will dtml-in always iterate over the rows display_news returns in order?
2. If so, is there a way for dtml-in to reverse the sort order?
3. If so, is it more efficient to let Zope or MySQL sort the data?
Thanks,
Ben