• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Looping over cfset tag

Guest
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

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?

TOPICS
Advanced techniques

Views

575

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

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."

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

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:
#

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

<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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

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#>
</cfloop>

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

<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]>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

Dan,
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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

LATEST
Try Form["Pick#i#"] instead of Form.pick#i#

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation