Query in ColdFusion

Hey guys,
     I'm fairly new to Dreamweaver/Coldfusion and was wondering how to do the following:
I have a database that I want to pull almost all the data from. For example, I have TableA with 26 fields, named A-Z in order respectively. I want to place this data into a HTML table (2x13), in a specific order that is not the order of the columns in my table. (e.g. C, Z, Y, Q…). How do I do that in one query (select * from TableA), but select the actual values from the specific fields to enter into my HTML table? That way, for each of the cells within the HTML table, I can insert the proper value from the query. Thanks.
               Sincerely,
                     JL
jl_forumAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

thack111Commented:
make the query:
<cfquery name='getdata' datasource='myDSN'>
    select *
    from tableA
</cfquery>
Then display it

<table>
<tr><th>heading1</th><th>heading2</th></tr>
<cfoutput query='getdata'>
      <tr><td>#B#</td><td>#A#</td></tr>
</cfoutput>
it will loop through the "<cfoutput>" tags till all records are displayed, and you can access the values by the field names, and put them in any order you want.

good luck
0
jl_forumAuthor Commented:
Actually, thats what I wanted to know. How exactly do you access the values? You mentioned by field names, but what does that mean? E.g. C.Value (?) I'm not sure. Thanks.
0
DanielSKimCommented:
This provides a somewhat dynamic solution, allowing you to specify in a single list the number of fields and the order you want the fields to be displayed. All you have to do is put in a comma delimited list the field order you want, from left to right. Example:

All you have to is the order, like this:
<cfset fieldOrder = "B,C,A,D">
And you will get:
B C
A D

You said you are fairly new to ColdFusion, so if you are unfamiliar with some of the CF functions i've used below, let me know what you would like me to explain.

<!---
<cfquery name="qryName" datasource="datasourceName">
select *
from tableName
</cfquery>
---->

<!---
*********************************************************************
- creates a sample query
- comment out, or delete the following block of code, when using the query above
*********************************************************************
--->
<cfset qryName = QueryNew("A,B,C,D")>
<cfset QueryAddRow(qryName)>
<cfset QuerySetCell(qryName, "A", "A")>
<cfset QuerySetCell(qryName, "B", "B")>
<cfset QuerySetCell(qryName, "C", "C")>
<cfset QuerySetCell(qryName, "D", "D")>
<!---
*********************************************************************
--->


<!---
*********************************************************************
set the field order here, putting in a comma-delimited list how you want the values to appear from left to right
*********************************************************************
--->
<cfset fieldOrder = "B,C,A,D">
<cfset numOfFields = ListLen(fieldOrder)>

<table>
<cfloop from="1" to="#numOfFields#" index="f">
  <cfset fieldName = ListGetAt(fieldOrder, f)>
  <cfset fieldValue = Evaluate("qryName." & fieldName)>
  <cfif f MOD 2 EQ 1>
  <tr>
  </cfif>
    <td><cfoutput>#fieldValue#</cfoutput></td>
  <cfif f MOD 2 EQ 0>
  </tr>
  </cfif>
</cfloop>
</table>
0
thack111Commented:
you can access the values of the fields, by
<cfoutput query='queryName'>
#fieldsName#
</cfoutput>
the above loops through all records.

or

<cfoutput>
#queryName.fieldName#
</cfoutput>
the above references the first record or the only record in a 1 record result.

You can put as much inside the <cfoutput> as you need to.
hope that helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jl_forumAuthor Commented:
Cool! =) Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.