[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Data has a variable

Posted on 2000-04-07
10
Medium Priority
?
163 Views
Last Modified: 2013-12-24
I have a table with 2 columns. One column is the name of a variable. The other column is the value for that variable. How can I get the data in Column one to be a variable?  For example. Column one has a value of "Var1" and Column two is "test". I need to be able to reference "VAR1" as <cfoutput>#var1#</cfoutput> with "test" as the result "test". IDEAS?
0
Comment
Question by:wills1300
  • 4
  • 3
  • 3
10 Comments
 
LVL 5

Expert Comment

by:nathans
ID: 2695116
Your loosing me...

you have a table in a database

datasource = MyDataSource
TableName  = MyTable
Columns    = Col1
             Col2

Data in table is
Col1             Col2
------------------------
Var1             Test


You want to be able to say
<cfoutput>#var1#</cfoutput>

and the actual output be

Test

=========================
If that is what your saying the
below code is the answer.
=========================
<cfquery name="MyQuery" datasource="MyDataSource">
Select *
From MyTable
Where Col1 = "Var1"
</cfquery>

<cfset Var1="#Col2#">

<html>
<head>
      <title></title>
</head>
<body>
Output:
<cfoutput>#Var1#</cfoutput>

</body>
</html>





When you call for Var1
             
0
 
LVL 2

Expert Comment

by:paulkd
ID: 2695197
Imagine that Col1 is your myquery.col1 and Col2 is your myquery.col2 ...

<CFSET Col1="Var1">
<CFSET Col2="test">

<CFSCRIPT>
'#Col1#' = #col2#;
</CFSCRIPT>

<CFOUTPUT>
#var1#
</CFOUTPUT>
0
 
LVL 2

Expert Comment

by:paulkd
ID: 2695257
paulkd changed the proposed answer to a comment
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
LVL 5

Expert Comment

by:nathans
ID: 2713154
Hello, wills1300 Are you there?
0
 

Author Comment

by:wills1300
ID: 2735210
Apologies for the delay. I had problems with my email.  

To refine what I was asking:

In essence I have 2 columns: name & value. There's 3 row of data as follow:

var1   "Today"
var2   "Tomorrow"
var3   "yesterday"

I want to be able to reference #var1# directly and have it output "Today" and so on for the other variables.  Does this make it any clearer?  

In the mean while I will try your suggestions. PAULKD could you expand on your suggestion. I don't quite understand what you have about "myquery.col1".

thanks.
0
 
LVL 2

Expert Comment

by:paulkd
ID: 2735731
Your query was called myquery... I just attempted to simulate the result of the query.

You can't have two columns of data and a third row.

It might be best if you simulated your table data in spreadsheet fashion, with actual data

0
 
LVL 5

Expert Comment

by:nathans
ID: 2735924
Explain to me why mine code does not do what you want.

you have what a table with two columns?

column 1
=========
var1
var2
var3

Column 2
=========

"Today"
"Tomorrow"
"yesterday"

you want to be able to say

#var2#

and the output would be

Tomorrow

If this is a correct assessment of what your asking then my code does just this.  If you tell me why my code does not do what you want then I will know what to do to fix it.

Nathan
0
 

Author Comment

by:wills1300
ID: 2736083
Nathans (&PAULKD)- Your suggestion would work - but it would require me to run a query for each "variable". I need something more 'dynamic' (if that's the right word). In addition the <CFSET VAR1 = 'col1'> is too static.  I would prefer not to use a <CFSET> tag. Right now I am using a structure to put all the variables with their values. So all I need to do is do a #structfind(name_of_structure, "var1")#, which would return "today".  I would prefer to make my code more basic - thus why I looking for another way to do this.

I guess, in creating these 'global variables' I don't want to have to name them specifically (as in using a cfset tag). Its only when I refer to them that I can refer to their specific names.

thanks,
0
 
LVL 2

Accepted Solution

by:
paulkd earned 800 total points
ID: 2736475
I wasn't suggesting using CFSET I just couldn't be bothered to write some CFQUERY code.

Where did 'global variables' come from? just to remind the viewers of the original plot

I have a table with 2 columns. One column is the name of a variable. The other column is the value for that variable. How can I get the data in Column one to be a variable?  For example. Column one has a value of "Var1" and Column two is "test". I need to be able to reference "VAR1" as <cfoutput>#var1#</cfoutput> with "test" as the result "test". IDEAS?

So....

A_Table

Col1VarName   Col2VarValue
Var1          Today
Var2          Tomorrow
Var3          Yesterday


The ColdFusion

<CFQUERY Name="X" datasource="history">
SELECT * from A_Table
</CFQUERY>

<CFOUTPUT QUERY="X">
<CFSCRIPT>
'#X.Col1VarName#' = #X.Col2VarValue#;
</CFSCRIPT>
</CFOUTPUT>

<CFOUTPUT>
#Var1#<br>#Var2#<br>#Var3#
</CFOUTPUT>


0
 

Author Comment

by:wills1300
ID: 2737735
That's it PAULKD - That's exactly what I wanted.

thanks.

thanks also NATHANS
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question