Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

FOREACH statement boo-boo

Ok, it's probably not a boo-boo!

I want to display all the articles in the folder EVENTS where the keyword="event", sorted by FiledDate.

The script is:

{$foreach x in (folder "events") sortAscendBy .filedDate$}
{$x.filedDate$} {$x.headline$}<p>
{$next$}

The output is beautifully sorted and I'm a happy camper.

Since there will be a bevy of volunteers inputting event listings into their own folder, there will be "event" listings in lots of folders that I want outputted.

My script is:

{$foreach x in (and (all) (keyword_contains "event")) sortAscendBy .filedDate$}
{$x.headline$}</A><p>
{$next$}


Oh no! The output is not in global date order!

FOREACH fetches the appropriate articles for subfolder1,
then sorts those records,
then html's them to my page;
then,
FOREACH fetches all the appropriate articles for subfolder2,
sorts 'em,
creates more html;
then so forth for each subsequent subfolder.

Is this my imagination? Have you experienced this too?

Joel: if the FOREACH statement resolves and sorts per folder, please add the ability for the FOREACH to fetch ALL the appropriate articles from ALL folders FIRST, then sort, then send output to html.

Bob Bloom
Wednesday, May 21, 2003

Did you mean for your script to be:

{$foreach x in (and (folder "events") (keyword_contains "event")) sortAscendBy .filedDate$}
{$x.headline$}</A><p>
{$next$}

Doing an "and" with the "all" constraint is redundant.  That may be the source of your sorting problems...

Michael H. Pryor
Wednesday, May 21, 2003

Michael, thanks for your reply.

I want my script to put all articles with the keyword "event" in all folders on the site into an event list table. Plus, all events s/b sorted by filedDate (which = event date).

Pseudo-code:

foreach article in [(all folders) and (keyword="event")] sortAscendBy .filedDate
{$x.headline$}
{$next$}

What is the CD script with the proper global sorting?

Many thanks :-)

-Bob

Bob Bloom
Wednesday, May 21, 2003

{$ foreach x in (keyword_Contains "event") sortAscendBy .filedDate $}
{$ x.headline $}
{$ next $}

You don't have to worry about the fact that you want "all folders"... that's understood.

Joel Spolsky
Wednesday, May 21, 2003

*  Recent Topics

*  Fog Creek Home