Skip to main content
Participating Frequently
May 5, 2008
Question

sorting/grouping results with CFDIRECTORY

  • May 5, 2008
  • 2 replies
  • 500 views
I am using cfdirectory to list all of the files in a certain directory and sorting them desc by datelast modified. Here's the page: http://www.ucmo.edu/news/releases/releases.cfm?y=2008

What I would like to do is sort them further by month and automatically create headings such as May, April, March, etc. I know how to get the monthasstring (in comments below) but can't get them grouped.

Here's what I use to display this page now:

<cfdirectory action="LIST" name="rel" directory="mydir/mysubdir" sort="month(datelastmodified) desc">

<ul>
<cfoutput query="rel">
<!--- #monthasstring(month(datelastmodified))#<br> --->

<li><img src="/home_images/icons/acrobat.gif" width="16" height="16" class="icon" alt=""> <a href="#y#/#name#" target="_blank">#replace(name,".pdf","")#</a></li>

</cfoutput>
</ul>


    This topic has been closed for replies.

    2 replies

    Inspiring
    May 5, 2008
    You will need to populate a column with month names before you can group by it. My approach would be:

    1. Do a Q of Q where I select the fields I need from the cfdirectory query, plus some contstant string as the month name.
    2. Loop through this query and set the month name column to the proper value.
    3. Output my data from this query, grouping on the month name column.
    Inspiring
    May 5, 2008
    use a QoQ (query of queries) on your cfdirectory query to get the info
    you need plus add any extra columns you need to be able to sort/group as
    necessary.


    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    rdk8487Author
    Participating Frequently
    May 5, 2008
    I've tried that to but can't seem to figure out the QoQ either. I'm still unable to group by month. I want it to look like:


    May
    My pdf1
    My pdf2

    April
    My pdf3
    My pdf4
    My pdf5