Solved

Data has a variable

Posted on 2000-04-07
10
149 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
 
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now