CFLOOP and Conditions
Hi, all,
I'm sure it's not as difficult as it seems, I think that my main problem is that I can't formulate what I want properly (in Coldfusion language that is).
I have an xml file on a cfc, I turned it into a query. From there I pull two queries
1- Category (listing the different task categories in my files).
2- Task (listing the different tasks according to their category).
Each task take a specific amount of time to perform (Nday).
What I am trying to do, is to take a random amount of tasks in each category, calculate their cumulative time, and display them. I only have 5 days in the week, so the cumulative time can't be over 5 days.
So far my code looks something like this:
<cfinvoke component="mycfc" method="xmltask" returnvariable = "qrtask">
<cfquery name="cat" dbType="query">
SELECT Category
FROM qrtask
GROUP BY Category
</cfquery>
<cfset tc = 0>
<cfset dd = 0>
<cfloop query="cat">
<cfquery name="Task" dbtype="query">
SELECT Task_Name, Nday
FROM qrtask
WHERE category = '#cat.category#'
</cfquery>
<cfset displayrow = randrange(1,task.recordcount)>
<cfoutput query="task" startrow="#displayrow#" maxrows="3">
#cat.category#
#Task_Name#
#Nday#
<cfset tc = Nday> <cfset dd = dd+tc> #dd#
</cfoutput>
</cfloop>
The whole thing seems to work pretty much the way I want to... except I can't calculate the total per category, I just get the total of the whole thing.
I don't really how to force the cfloop to go from one category to another (so my idea to use something like <cfif dd less than 5> did not really work).
Ideally the query should reloop until "dd" is as close to 5 as possible, then move on to the next category (I can have only one 5 days tasks, five 1 day tasks or anything in between).
I'll exchange my famous chili con carne recipe against any light on the subject... (even though bean and light should not probably mix all that much
)
