Solved

Data has a variable

Posted on 2000-04-07
10
153 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
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 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
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 …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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