Robert writes in with a question concerning CFPOP:
I have put together a little webail app for my website and for the most part it works pretty good but.... It returns the mail messages in a seemingly random order. Is there a way to order the results?
I could have sworn that I remember CFPOP returning items in order of delivery. In other words, the first message sent to the account would be the first downloaded. The documentation for cfpop does not specify an order, so I probably wouldn't depend on any order.
That being said - don't forget that the result of cfpop is a query. Because of this, you can use query of query to sort the results. You can sort by sender, date, subject, or any other column. Here is a simple example:
<cfpop server="pop.xxx.com" username="..." password="..." action="getHeaderOnly" name="qGetMessages">
<cfquery name="qGetMessages" dbtype="query">
select *
from qGetMessages
order by date desc
</cfquery>
Archived Comments
good cookbook entry
Maybe so - although I'd probably make it more general. "How can I reorder a database query?"
maybe another cookbook post would be a general description on the MANY different tags that return a query object (like cfdirectory, etc) - when i was a noob, i didn't quite understand the concept of anything other than the results of a cfquery being a query object...
or is this already on the cookbook? don't remember and too lazy to go check... i swear i _have_ seen a post like this recently somewhere...
i tried it using various ways but encounter with with error:
The error occured when i tried something like this:
SELECT date as pdate, subject, messagenumber
FROM qGetMessages
ORDER BY pdate DESC
and tied like this also:
SELECT qgTemessages.*,qGetmessages.date as pdate
FROM qGetMessages
ORDER BY pdate DESC
Error Executing Database Query.
Query Of Queries syntax error.
Encountered "date. Incorrect Select List, Incorrect select column,
my query was:
SELECT *
FROM qGetMessages
ORDER BY date DESC
with the above once error was:
Query Of Queries syntax error.
Encountered "date. Incorrect ORDER BY column reference [date].
Only simple column reference, alias name, and integer column id are allowed.
Example: You can use alias to refer to a complex expression:
SELECT (a+b)/2 as x FROM T ORDER BY x
Escape it. Use [date].