Hi Lewis

What database are you using?
I am not sure exactly what you are doing with the arrays but if I had a data 
base 
with a bunch of years in it I would do a query for the distinct years and then 
a 
query within the year:

<cfquery datasource="yourdataSource" name="year">
SELECT DISTINCT year
FROM    database
ORDER BY year
</cfquery>

Then I would creat a loop
<cfloop from="1" to="#year.recordCount#" index="y">

<cfquery datasource="yourdataSource" name="yearItems">
SELECT *
FROM    database
WHERE year = <cfqueryparam cfsqltype="cf_sql_date" value="#year[y]#"> 
</cfquery>

<cfoutput>
<h1>#year[y]#</h1>

<!--- Create Your Output Table Here for the Year--->
<cfloop from="1" to="#yearItems.recordCount#" index="z">
<table>
<tr>
<td>yearItems.Whateverdata[z]</td> etc
</tr>
</table>
</cfloop>
</cfoutput>
</cfloop>

Hope this helps and best of luck mate
Rob
Robert J. Voyle, Psy.D.
Director, Clergy Leadership Institute
For Coaching and Training in Appreciative Inquiry
Author: Restoring Hope: Appreciative Strategies
            to Resolve Grief and Resentment
http://www.appreciativeway.com/
503-647-2378 or 503-647-2382



On 29 May 2013 at 9:22, Lewis Billingsley wrote:

> 
> HI Bill
> 
>     Thanks for responding.  This sounds very interesting, and I
> would like
> to explore it, but I had a problem using a structure for the way I'm
> using
> the code after I get the dates.  More importantly, I'm under the gun
> to
> come up with a solution right away.  I know it's klugy, but if you
> could
> help me with just telling me how to write a query so that it only
> returns
> dates where the year is 2014 or whatever, that would solve my
> immediate
> problem.  Then I can just write the 3 or 4 queries and get this in
> on
> time.  Later, then I can explore what you are talking about.
> 
> Thanks much,
> Lewis
> 
> On Tue, May 28, 2013 at 7:38 PM, Bill Moniz <[email protected]>
> wrote:
> 
> >
> > 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:
> 6081
> Subscription:
> http://www.houseoffusion.com/groups/cf-newbie/subscribe.cfm
> Unsubscribe:
> http://www.houseoffusion.com/groups/cf-newbie/unsubscribe.cfm




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:6082
Subscription: http://www.houseoffusion.com/groups/cf-newbie/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-newbie/unsubscribe.cfm

Reply via email to