9 Replies Latest reply on Mar 19, 2007 2:16 PM by Newsgroup_User

    Looping over cfset tag

      Hey Guys,

      I am having a problem with cfloop. What I am trying to do is calculate points on an Oline March Madness Pool. I need to evaluate if the user picks are equal to the game winners. I can do it if I manually type each pick # and each game # but I would much rather loop over a cfset tag since there are 63 picks and games. You can check out my code below to get a better idea of what I am trying to do. While I know I can't include the #'s on the right side of the cfset tag in this way I included them anyways to better illustrate where I would like to loop it. Is there a way to do this, or will I have to manually set each pick?

        • 1. Re: Looping over cfset tag
          Level 7
          So which lines are causing problems and what kind of problems do you have.

          "Yes, I can see some issues, but before I jump and and fully analyze
          your code, I would like to here more from you."
          • 2. Re: Looping over cfset tag
            Dan Bracuk Level 5
            This would be a lot easier if you had a table that looked like this:

            playerID, GameID, Pick, Result

            Then all you would have to do is
            select playerID, count(playerID) points
            from yourtable
            where pick = result
            • 3. Re: Looping over cfset tag
              Woody1980 Level 1
              I am having an issue at the nested cfloop tag. I cannot get the csfet tag to loop. It keep getting the error:

              Invalid CFML construct found on line 27 at column 46.
              ColdFusion was looking at the following text:

              • 4. Re: Looping over cfset tag
                Level 7
                <cfif getGames.game#l# EQ userPoints[#userID#]["pick#l#"]>

                I'm going to guess this is line 27 or very near it.

                Your actual <cfset> line looks fine to me assuming all the relevant keys
                exist when they need to exist. I would have written it something like:

                <cfset userPoints[userID]["pick" & i] = variables["pick" & i]>

                The if statement should probably look like this:
                <cfif getGames["game" & i] EQ userPoints[userID]["pick" & i]>

                All your index variables are the letter "i" and not the number "1"
                aren't they? I don't believe a singe number is a valid CF variable name.

                • 5. Re: Looping over cfset tag
                  Woody1980 Level 1
                  Thank you very much for your response. However, I would need to change the amount of points given in the second round to 2 instead of 1. Then in round 3 I would need to add 3 points instead of 1. Would this incremental point system work with your method?
                  • 6. Looping over cfset tag
                    Dan Bracuk Level 5
                    If you add a round_number field, you could do something like this

                    select playerId, sum(points) total_points
                    from (
                    select playerID, round_number, count(playerID) * round_number points
                    from yourtable
                    where pick = result
                    group by playerID, round_number ) temp
                    group by playerID

                    It would get a bit more complicated if you wanted to display those with no points, but not much.
                    • 7. Re: Looping over cfset tag
                      Woody1980 Level 1
                      This is driving me crazy!!

                      Dan I will be trying your method but now I have to figure this out.

                      How do you loop over cfset tag expressions? While I can loop over the name of it ok I can NEVER loop over the expression.

                      For Example this wouldn't work:
                      <cfset picks = structNew()>
                      <cfloop index="i" from="1" to="5">
                      <cfset picks["pick#i#"] = form.pick#i#>

                      In trying to do this I am told that I can't use either the # or ? in the expression. Why is this? It is maddening when you have set up a structure.

                      Am I doing something wrong? Is there another way to do this?
                      • 8. Re: Looping over cfset tag
                        Level 7
                        <cfset picks["pick#i#"] = form.pick#i#>

                        The left side of your expression is just fine, it is the right that is
                        wrong! :-)

                        Try something like:
                        <cfset picks["pick#i#] = form["pick#i#]>

                        OR my preferred:
                        <cfset picks["pick" & i] = form["pick" & i]>

                        • 9. Re: Looping over cfset tag
                          insuractive Level 3
                          Try Form["Pick#i#"] instead of Form.pick#i#