[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Data has a variable

Posted on 2000-04-07
10
Medium Priority
?
161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 
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

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

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

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

649 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