Ok...How about this:

1. Set up a struct called dateArrays: <cfset dateArrays = {} />

2. Do your single query as you are already, so you get back a recordset of
dates. (I'll assume the query is called "dateQuery" and the column with the
dates in it is called "date")

3. Loop over the query.

  At each iteration, check if you have a struct key defined for the year of
the date you're looking at currently.  If you don't, create one and stick
an empty array in there:

<cfif !structKeyExists(dateArrays, year(dateQuery.date))>
    <cfset dateArrays[year(dateQuery.date)] = [] />
</cfif>

Add the date you're looking at currently to the appropriate array in your
struct:
<cfset arrayAppend(dateArrays[year(dateQuery.date)], dateQuery.date) />

4. At the completion of your loop you should have a nice structure, with a
key for each distinct year in your recordset, and the values being arrays
of the dates that fall within that year.

Now, I haven't actually run this code, but I'm convinced the theory is
sound. ;)

Cheers,
Bill.



On 29 May 2013 08:43, Lewis Billingsley <[email protected]> wrote:

>
> Thanks for responding Nick.
>
>     The dates simply come from a database query, actually a query of a
> stored procedure.  There is a simple recordset of dates.  There may be 4 or
> 5 years.  It would be best if the query to array could happen just using
> the one query.  But, if I can't figure out how to do this that way, I would
> be happy to have the 4 or 5 queries.  But, I don't know what the code would
> be to inject a <cfif statement in the query that would get, say, only the
> dates that are in 2014.  Can you help me figure this out?
>
> Thanks much,
> Lewis
>
>
>
>
> On Tue, May 28, 2013 at 2:53 PM, Eric Nicholas Sweeney <
> [email protected]> wrote:
>
> >
> > Lewis...
> >
> > How many years of data do you have?
> >
> > A few things come to mind..  You could have separate queries for each
> > year... (clumsy but effective) Or tie a cfDiv to your query - based on
> year
> > passed to the div...
> >
> > The page...
> > <cfform>
> >     <cfinput type="text" name="MyYear" value="#FORM. MyYear#" />
> > </cfform>
> >
> > <h3>Results </h3>
> > <cfdiv bind="url:MyResultsTable.cfm? MyYear ={MyYear}" bindonload="true"
> />
> >
> >
> > ---
> > The Query... OnMy ResultsTable.cfm...
> >
> > SELECT Data
> > FROM Table
> > WHERE Year = <cfqueryparam value="#URL.MyYear#">
> >
> > This isn't final code - but it should help...  Additionally - you could
> > have the cfinput be a select - with Year drop down... looping from "this
> > year" to earliest  year...
> >
> > - Nick
> >
> >
> >
> >
> >
> >
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-newbie/message.cfm/messageid:6080
Subscription: http://www.houseoffusion.com/groups/cf-newbie/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-newbie/unsubscribe.cfm

Reply via email to