|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
|
|
#1
|
|||
|
|||
|
Using a predefined variable in query output
I have what I had initially thought was a relatively easy request, however it hasn't quite proved that way, at least not just yet. With any luck I'm missing something simple.
A working example is easiest to start with: <cfoutput query="results"> <tr bgcolor="#IIf(CurrentRow Mod 2, DE('ffffff'), DE('cccccc'))#"> <td>#team_name#</td> <td>#round1#</td> <td>#total_score#</td> </tr> </cfoutput> From a previous query (results) I want to output in a table the results for each of the columns listed above; team_name, round1, and total_score - but I dont want to have to hard code round1, since that will depend on the round number. This is already set as another variable (called round_number). However, when I try the following: <cfoutput query="results"> <tr bgcolor="#IIf(CurrentRow Mod 2, DE('ffffff'), DE('cccccc'))#"> <td>#team_name#</td> <td>#round("#round_number#")#</td> <td>#total_score#</td> </tr> </cfoutput> it outputs 1 repeatedly (which is the current round_number) in the middle column. As I have outlined, this is not what I want. I want the value from the column round(#round_number#), which in this case is round1. Does that make sense? All help greatly appreciated. adieu Mark |
|
#2
|
|||
|
|||
|
So are you saying that you don't want to hard code "round1" because sometimes it might be "round2", "round7", etc?
If that's the case, you could do something like: <cfset round_number = "round1" /> <cfoutput query="results"> <tr bgcolor="#IIf(CurrentRow Mod 2, DE('ffffff'), DE('cccccc'))#"> <td>#team_name#</td> <td>#round( evaluate( 'round_number' ) )#</td> <td>#total_score#</td> </tr> </cfoutput> You could probably do this without using evaluate, and instead using the array-like syntax for referencing the query column, but I wanted to see if this is what you are trying to achieve before I make things more complex.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
<snip>
So are you saying that you don't want to hard code "round1" because sometimes it might be "round2", "round7", etc? </snip> Yes, that's exactly what would happen. However, when I try your example I run into the same trouble as previously outlined: #round( evaluate( 'round_number' ) )# only outputs the number 1 repeatedly, as opposed to making the query and pulling data from the round1 column. Help! |
|
#4
|
|||
|
|||
|
*smacks forehead* Here is a working solution..
<cfoutput query="results"> <tr bgcolor="#IIf(CurrentRow Mod 2, DE('ffffff'), DE('cccccc'))#"> <td>#team_name#</td> <td>#results["round_#round_number#"][currentRow]#</td> <td>#total_score#</td> </tr> </cfoutput> regards Mark |
|
#5
|
|||
|
|||
|
LOL, that's exactly the solution I was talking about when I mentioned doing it with the query array syntax. You jumped right to it, very nice.
Also, I think I just forgot the pound signs...I think this would also work: #round( evaluate( '#round_number#' ) )# |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Using a predefined variable in query output |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|