|
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Won't evaluate?
I have in my DB under the field of answer...Phillip M. Vector 10/09/08 09:43 P cf won't evaluate your variable inside a variable (#users.recordcount#Azadi Saryev 10/09/08 09:53 P So why isn't this working then?Phillip M. Vector 10/10/08 02:45 P Is it inside a loop over a query? If so then scope your outputed variablesAaron Rouse 10/10/08 02:54 P Here's the full code.Phillip M. Vector 10/10/08 03:02 P >>Replace(FAQ.Question, '$$UserCount$$', usercount, "ALL")Claude Schneegans 10/10/08 03:08 P Claude Schneegans wrote:Phillip M. Vector 10/10/08 03:13 P Just wondering out loud... Is it possibly treating $$ as $, like forDave Francis 10/10/08 03:43 P -----BEGIN PGP SIGNED MESSAGE-----rex 10/10/08 03:13 P Like I said if it is in a loop over a query then you need to scope theAaron Rouse 10/10/08 03:24 P >Is it inside a loop over a query? If so then scope your outputed variablesPeter Boughton 10/10/08 03:02 P I'm just using a cfoutput querry loop.Phillip M. Vector 10/10/08 03:06 P >I'm just using a cfoutput querry loop.Peter Boughton 10/10/08 03:16 P Thanks for the explination. I understand the issue now. :)Phillip M. Vector 10/10/08 03:29 P Phillip M. Vector wrote:Ian Skinner 10/10/08 03:22 P Ian Skinner wrote:Phillip M. Vector 10/10/08 03:27 P While the naming is bad, why not learn from the experience and try to scopeAaron Rouse 10/10/08 03:32 P I used to not scope and had to teach myself to scope and break thatEric Roberts 10/10/08 04:20 P I became a scoping nazi back when I had to start working with a home builtAaron Rouse 10/10/08 04:23 P Phillip M. Vector wrote:Ian Skinner 10/10/08 03:34 P Ian Skinner wrote:Phillip M. Vector 10/10/08 03:42 P >>Yes, I know scoping my variables is aClaude Schneegans 10/10/08 04:34 P We all have our slow days Philip :-D It's a good thing slapping of theEric Roberts 10/10/08 04:18 P >So why isn't this working then?Peter Boughton 10/10/08 02:55 P Peter Boughton wrote:Phillip M. Vector 10/10/08 03:01 P >>So why isn't this working then?Claude Schneegans 10/10/08 02:56 P I know.. I know.. It isn't pretty code.. But it's how I learned how toPhillip M. Vector 10/10/08 03:00 P > old habbits are hard to break.Peter Boughton 10/10/08 03:06 P Heh.. True enough.Phillip M. Vector 10/10/08 03:07 P The short answer is: you don't.Matt Quackenbush 10/09/08 09:56 P Ok.. Thanks. :)Phillip M. Vector 10/09/08 10:21 P >I have in my DB under the field of answer...Ian Skinner 10/10/08 05:58 P Thanks! :) This makes it allot easier. :)Phillip M. Vector 10/10/08 06:06 P Ian Skinner wrote:Ian Skinner 10/10/08 06:14 P Yeah but you have to be careful with how much you use those functions in anAaron Rouse 10/10/08 08:06 P And finally, do you really want a user to be able to add any random CFJames Holmes 10/10/08 08:45 P I have in my DB under the field of answer... We have currently #users.recordcount# players signed up with this site that your event would reach. While it may not be many in the pure view, if 7 come to your convention, that would pay for our services (Figuring the room costs a total of $200 and you charge $30 for admission). Any above that can't hurt your bottom line. exactly. The #users.recordcount# as well. When I run this code.. <cfoutput query="FAQ"> <div class="FAQAnswer"> #Evaluate("FAQ.Answer")# </div> </cfoutput> It shows #users.recordcount# (with the pound signs) and not 32 like I would think it would.. I tried also just putting #FAQ.Answer#, but that doesn't work either. How do I make CF treat data it pulls from the DB as variables and not a string? cf won't evaluate your variable inside a variable (#users.recordcount# inside #FAQ.answer"). you best bet will be to either store that text in a cfm file and cfinclude it, or do it on the fly by pulling that text from db, writing it to a temp file and cfinclude that file. another alternative may be to get your users.recordcount number in a variable in the page that displays the answer, and in your text in db store a placeholder, like $$usersnumber$$, and then at cfoutput replace the placeholder text with the actual number from the variable in the page. hth Azadi Saryev Sabai-dee.com http://www.sabai-dee.com/ Phillip M. Vector wrote: ----- Excess quoted text cut - see Original Post for more ----- So why isn't this working then? <cfset UserCount = #Users.Recordcount#> <cfset Question = #Replace(FAQ.Question, '$$UserCount$$', #usercount#, "ALL")#> <cfset Answer = #Replace(FAQ.Answer, '$$UserCount$$', #usercount#, "ALL")#> <a name="#FAQ.FAQID#"></a> <div class="FAQQuestion"> #Question# </div> <P> <div class="FAQAnswer"> #Answer# </div> Azadi Saryev wrote: > another alternative may be to get your users.recordcount number in a > variable in the page that displays the answer, and in your text in db > store a placeholder, like $$usersnumber$$, and then at cfoutput replace > the placeholder text with the actual number from the variable in the page. Is it inside a loop over a query? If so then scope your outputed variables in those div elements. Also do not need the pound signs in your two cfsets both on the replace functions and the usercount variables. On Fri, Oct 10, 2008 at 1:40 PM, Phillip M. Vector < Vector@mostdeadlygame.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- Here's the full code. <cfoutput query="FAQ"> <cfset UserCount = Users.Recordcount> <cfset Question = Replace(FAQ.Question, '$$UserCount$$', usercount, "ALL")> <cfset Answer = Replace(FAQ.Question, '$$UserCount$$', usercount, "ALL")> <a name="#FAQ.FAQID#"></a> <div class="FAQQuestion"> #Question# </div> <P> <div class="FAQAnswer"> #Answer# </div> <HR> </cfoutput> So yeah. it's looping fine. Just doesn't show any usercount. Aar > Is it inside a loop over a query? If so then scope your outputed variables > in those div elements. >>Replace(FAQ.Question, '$$UserCount$$', usercount, "ALL") It may also be an question of upper/lower case. Are you sure you always have "UserCount" ? If not, use replaceNoCase() instead. >>just doesn't show any usercount. Does it show any '$$UserCount$$' then ? Claude Schneegans wrote: > >>Replace(FAQ.Question, '$$UserCount$$', usercount, "ALL") > > It may also be an question of upper/lower case. > Are you sure you always have "UserCount" ? > If not, use replaceNoCase() instead. It's exactly that. > >>just doesn't show any usercount. > > Does it show any '$$UserCount$$' then ? Yes. Here is what it shows.. =========================== What is LARP? $$UserCount$$ Just wondering out loud... Is it possibly treating $$ as $, like for quotes and hashes? Also, try it without any variables ie. Replace("ABC $$UserCount XYZ", '$$UserCount$$', "999", "ALL"), then introduce them 1 at a time until it breaks. Claude Schneegans wrote: > >>Replace(FAQ.Question, '$$UserCount$$', usercount, "ALL") > > It may also be an question of upper/lower case. > Are you sure you always have "UserCount" ? > If not, use replaceNoCase() instead. It's exactly that. > >>just doesn't show any usercount. > > Does it show any '$$UserCount$$' then ? Yes. Here is what it shows.. =========================== What is LARP? $$UserCount$$ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Like Aaron and Peter said, SCOPE your variables like so: <cfoutput query="FAQ"> <cfset VARIABLES.UserCount = Users.Recordcount> <cfset VARIABLES.Question = Replace(FAQ.Question, '$$UserCount$$', VARIABLES.usercount, "ALL")> <cfset VARIABLES.Answer = Replace(FAQ.Question, '$$UserCount$$', VARIABLES.usercount, "ALL")> <a name="#FAQ.FAQID#"></a> <div class="FAQQuestion"> #VARIABLES.Question# </div> <P> <div class="FAQAnswer"> #VARIABLES.Answer# </div> <HR> </cfoutput> When you are referencing #Question# you are actually referencing #FAQ.Question# and not #VARIABLES.Question#, so it wont work Phillip M. Vector wrote: ----- Excess quoted text cut - see Original Post for more ----- Like I said if it is in a loop over a query then you need to scope the variables within the div elements. That is your problem. On Fri, Oct 10, 2008 at 1:57 PM, Phillip M. Vector < Vector@mostdeadlygame.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- >Is it inside a loop over a query? If so then scope your outputed variables >in those div elements. That sounds likely to be the problem - CF will give priority to the query vars in resolving unscoped variables. To clarify a little, the possible solutions are: 1) Scope the variable, e.g. using #Variables.Question# instead of just #Question# 2) Overwrite the values in the query, i.e. <cfset FAQ.Question[CurrentRow] = replace(...) > I'm just using a cfoutput querry loop. But I put in [CurrentRow] just in case. No change. Still not working. Peter Boughton wrote: ----- Excess quoted text cut - see Original Post for more ----- >I'm just using a cfoutput querry loop. > >But I put in [CurrentRow] just in case. No change. Still not working. Not sure if you're understanding fully, so I'll simplify completely: (apologies if any of this is patronising) This code here: <cfoutput query="FAQ"> #Question# </cfoutput> Will do the same as this: <cfoutput query="FAQ"> #FAQ.Question[FAQ.CurrentRow]# </cfoutput> If you did this: <cfoutput query="FAQ"> <cfset Variables.Question = "X"/> #FAQ.Question[FAQ.CurrentRow]# </cfoutput> You wouldn't be surprised that the output didn't change (I hope). The following is IDENTICAL to ColdFusion as the above code: <cfoutput query="FAQ"> <cfset Variables.Question = "X"/> #Question# </cfoutput> And this code is also IDENTICAL to ColdFusion as both the above: <cfoutput query="FAQ"> <cfset Question = "X"/> #Question# </cfoutput> In other words, when you *set* the variable Question, it goes into the global Variables scope. However, when you *read* the variable Question, because you are looping through the query, it looks first in the query's scope. This is one of the reasons you find many people saying you should always scope all variables - it avoids issues like this. To make things work as you want, you need to either read the global Variables scope, or instead to change the value within the query scope. All make sense? Thanks for the explination. I understand the issue now. :) Peter Boughton wrote: ----- Excess quoted text cut - see Original Post for more ----- Phillip M. Vector wrote: > Peter Boughton wrote: > >> 1) Scope the variable, e.g. using #Variables.Question# instead of just #Question# Did you do this one Phillip. I'm late to this discussion so I don't really know what your issue is. But you have some pretty ambiguous code here. <div class="FAQQuestion"> #Question# </div> Is ColdFusion seeing that as 'variables.question' or 'variables.FAQ.question' you have both on this block of code. And it may not be picking the one you want to output. If so then be specific in which one you want. Ian Skinner wrote: > <div class="FAQQuestion"> > #Question# > </div> > > Is ColdFusion seeing that as 'variables.question' or 'variables.FAQ.question' you have both on this block of code. And it may not be picking the one you want to output. If so then be specific in which one you want. OOOohhh.... *slaps forehead* I get the idea now.. Thanks. I can name them Q and A and use that (Yup. Tried it and it works). Yeah... I feel stupid now. :) While the naming is bad, why not learn from the experience and try to scope things? It could save you a lot of random headaches over the years. On Fri, Oct 10, 2008 at 2:22 PM, Phillip M. Vector < Vector@mostdeadlygame.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- I used to not scope and had to teach myself to scope and break that habit...next one I am working on is cfqueryparam... One day at a time... Maybe we need to create a 12 step program for CF developers hehehe *grin* Eric /*-----Original Message----- /* /*Sent: Friday, October 10, 2008 2:28 PM /*To: cf-talk /*Subject: Re: Won't evaluate? /* /*While the naming is bad, why not learn from the experience and try to /*scope /*things? It could save you a lot of random headaches over the years. /* /*On Fri, Oct 10, 2008 at 2:22 PM, Phillip M. Vector < /*Vector@mostdeadlygame.com> wrote: /* /*> Ian Skinner wrote: /*> > <div class="FAQQuestion"> /*> > #Question# /*> > </div> /*> > /*> > Is ColdFusion seeing that as 'variables.question' or /*> 'variables.FAQ.question' you have both on this block of code. And it /*may /*> not be picking the one you want to output. If so then be specific in /*which /*> one you want. /*> /*> OOOohhh.... *slaps forehead* I get the idea now.. Thanks. I can name /*> them Q and A and use that (Yup. Tried it and it works). Yeah... I feel /*> stupid now. :) /*> /*> /* /* I became a scoping nazi back when I had to start working with a home built framework that did not scope a single thing. It made it rather difficult to back track through things and see how it was supposed to be working(since it did not always work right). On Fri, Oct 10, 2008 at 3:13 PM, Eric Roberts < owner@threeravensconsulting.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- Phillip M. Vector wrote: ----- Excess quoted text cut - see Original Post for more ----- Or just be specific in what you wanted to output. Modifying your original code in the following manner will achieve the exact same result as changing the variable names, and demonstrates a better practice of scoping your variables. I hope you at least wrote that as 'variables.q' and 'variables.a'! :-) <div class="FAQQuestion"> #variables.Question# </div> Ian Skinner wrote: > Or just be specific in what you wanted to output. Modifying your > original code in the following manner will achieve the exact same result > as changing the variable names, and demonstrates a better practice of > scoping your variables. I hope you at least wrote that as 'variables.q' > and 'variables.a'! :-) Fair enough. No, I didn't actually name them Q and A. :) I named them "AdjustedQuestion" and "AdjustedAnswer". As for putting variable. before every variable will take quite a bit of work for the app I'm working on. Yes, I know scoping my variables is a good thing now and I will from now on when needed. But honestly, it so rarely comes up as an issue (I don't know what I was doing naming the variable the same name as the field) that it seems redundant to do so (well, until something like this happens). :) >>Yes, I know scoping my variables is a good thing now and I will from now on when needed. But honestly, it so rarely comes up as an issue Right. A good practice to avoid trouble if you don't scope is at least to use different names for variables in different scopes, especially with queries. The problem with queries is that inside a <CFOUTPUT on a query, the query scope become implicit and have precedence over the variables scope, but not outside. Using different names will prevent confusions. Like in your case <cfset FAQQuestion = Replace(FAQ.Question instead of <cfset Question = Replace(FAQ.Question We all have our slow days Philip :-D It's a good thing slapping of the forehead doesn't leave permanent marks...I would be so disfigured if that were the case hehehe. Eric /*-----Original Message----- /* /*Sent: Friday, October 10, 2008 2:23 PM /*To: cf-talk /*Subject: Re: Won't evaluate? /* /*Ian Skinner wrote: /*> <div class="FAQQuestion"> /*> #Question# /*> </div> /*> /*> Is ColdFusion seeing that as 'variables.question' or /*'variables.FAQ.question' you have both on this block of code. And it may /*not be picking the one you want to output. If so then be specific in /*which one you want. /* /*OOOohhh.... *slaps forehead* I get the idea now.. Thanks. I can name /*them Q and A and use that (Yup. Tried it and it works). Yeah... I feel /*stupid now. :) /* /* >So why isn't this working then? > > [snip] Not sure - make sure the database contains this text: "We have currently $$UserCount$$ players signed up with this site" ? Also, your code has far too many hashes - here it is cleaned up a little: <cfset UserCount = Users.RecordCount> <cfset Question = Replace( FAQ.Question , '$$UserCount$$' , UserCount , "ALL" )> <cfset Answer = Replace( FAQ.Answer , '$$UserCount$$' , UserCount , "ALL" )> <cfoutput> <div class="FAQQuestion" id="#FAQ.FAQID#"> #Question# </div> <div class="FAQAnswer"> #Answer# </div> </cfoutput> Peter Boughton wrote: > Not sure - make sure the database contains this text: > "We have currently $$UserCount$$ players signed up with this site" Yup. That's all that is in the field. >>So why isn't this working then? >> <cfset UserCount = #Users.Recordcount#> >> <cfset Question = #Replace(FAQ.Question, '$$UserCount$$', #usercount#, "ALL")#> You're not using # signs correctly : <cfset UserCount = Users.Recordcount> <cfset Question = Replace(FAQ.Question, '$$UserCount$$', usercount, "ALL")> # sign should be used only inside <CFOUTPUT tags, rarely inside other CF tags. But this may not be the only reason. I know.. I know.. It isn't pretty code.. But it's how I learned how to do it and old habbits are hard to break. I seriously doubt that the #'s are messing things up. Yup. Cleaned it up and it's still not displaying correctly. Claude Schneegans wrote: ----- Excess quoted text cut - see Original Post for more ----- > old habbits are hard to break. If you have someone kick you every time you do it, you can break most habits much quicker. :) Heh.. True enough. Peter Boughton wrote: > If you have someone kick you every time you do it, you can break most habits much quicker. :) The short answer is: you don't. The longer version is, you can setup placeholders and do a replace on them to enter the values that you're wanting to use. On Thu, Oct 9, 2008 at 8:38 PM, Phillip M. Vector wrote: > How do I make CF treat data it pulls from the DB as variables and not a > string? > Ok.. Thanks. :) Matt Quackenbush wrote: ----- Excess quoted text cut - see Original Post for more ----- ----- Excess quoted text cut - see Original Post for more ----- Going back to you original question, contrary to Azadi's and Matt's answers, you can do this. I am not sure this is better then the replacement technique that has already been worked out, but in the names of fairness and completeness. You could have done something like this. <cfoutput query="FAQ"> <div class="FAQAnswer"> #Evaluate(DE(FAQ.Answer))# </div> </cfoutput> It requires a combination of the de() 'delay evaluate' and evaluate() functions to get ColdFusion to render variables contained inside of string variables. No guarantees on how robust this solution is, but it is technically possible. Thanks! :) This makes it allot easier. :) Ian Skinner wrote: ----- Excess quoted text cut - see Original Post for more ----- Ian Skinner wrote: ----- Excess quoted text cut - see Original Post for more ----- O.K.!!!! I have never really done anything with this recursive rendering of ColdFusion variables inside of ColdFusion variables before. But this is kind of cool to my geeky soul!!! In a very much, 'Why the hell would you ever do this!' way <cfset aString = "Here is some ##change_this## text."> <cfset change_this = "(The quick brown fox jumped ##myOhMy## over the lazy dog.)"> <cfset myOhMy = "{{You have got ##no_do_not_do_it## to be kidding!}}"> <cfset no_do_not_do_it = "[[[Stop this madness now!!!!]]]"> <cfoutput> #aString# <hr /> #evaluate(de(aString))# <hr /> #evaluate(de(evaluate(de(aString))))# <hr /> #evaluate(de(evaluate(de(evaluate(de(aString))))))# <hr /> </cfoutput> Yeah but you have to be careful with how much you use those functions in an application. I know at least on our CF6 server here for one project that extensively uses those it does in fact eat up a good bit of resources when a normal user load is on it. ----- Excess quoted text cut - see Original Post for more ----- |