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

Recommended Answers

All 4 Replies

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.

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

Thanks for the help, it works great! :)

No problem, just mark this thread as solved. :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.