0

Hello I'm new to ColdFusion, for my work I've been asked to learn it..

I'm coming from an extensive PHP background. For the life of me I cannot figure out how to simply take a query from SQL and load it into an array and then display it. I though this would be a very simple task which has become a headache.

Anyhow come code:

<!--- Show user details --->
<cfquery name="at" datasource="sql">
SELECT * FROM tbladmins
</cfquery>

<cfset FieldIArray = ListToArray(at)>


<cfoutput>#FieldIArray[0]#</cfoutput>

The error lies in the cfset field, I don't understand how I can extract data from the query?

Can someone help thanks..

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by cfwebdeveloper
0

cfquery returns information as a structure so if you want to exact data you can use queryname.columnname so in this case for example #at.username# would return whatever the first row of the query is.

You can use cfdump to view what the query is returning by doing cfdump(#at#).

Line 6 errors because cfquery does not return a list, it is a structure.

If you want to loop the query:

<cfloop query="at">
   <cfoutput>#at.lastName#, #at.firstName# <br /></cfoutput>
</cfloop>

OR

<cfoutput query="at">
   #at.lastName#, #at.firstName#
</cfoutput>

lastName and firstName would be my guess of column names since you used *

Let me know if this helps, you really dont need to convert this to an array unless there is more behind the question.

Edited by cfwebdeveloper: n/a

0

I'll get back to you on Sunday night (at a lan event). Thanks for the help!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.