CFScript query loop

233 views
Skip to first unread message

jcreamer898

unread,
Sep 29, 2010, 3:16:09 PM9/29/10
to ColdBox Platform
This is not exactly a coldbox related question, but I am using the
cfscript query stuff,

// Get Entries List
result function getEntries()
{
var query = new Query(datasource="mps", sql="SELECT title,contents
FROM blogs");
var oResults = query.execute();

return oResults;
}

And was wondering what the best way to do loops of queries is now.
Cleary, the object passed back now from query.execute() is a result. I
have tried

<cfloop query="rc.entries.getResult()">
</cfloop>

With no success...

This works here:

var oResults = query.execute();
var numRes = oResults.getPrefix().recordcount;
var qResults = oResults.getResult();

for(var i = 1; i <= numRes; i++)
{
WriteOutput(query["title"][i]);
WriteOutput(query["contents"][i]);
}

But is that the best way of doing things now?

Kevin S. Anderson

unread,
Sep 29, 2010, 3:42:01 PM9/29/10
to col...@googlegroups.com
Recommend modifying your code to the following:

Var oResults = query.execute().getResult();

You can then perform the following:

for( i=1; I LTE oResults.recordCount; i++ ) {
writeOutput(oResults.field[i]);
}

The query.execute() method returns an object that has the result set
buried inside of it, whereas using the getResult() method give you a
standard query result recordset.

Kevin

return oResults;
}

<cfloop query="rc.entries.getResult()">
</cfloop>

With no success...

This works here:

--
You received this message because you are subscribed to the Google
Groups "ColdBox Platform" group.
To post to this group, send email to col...@googlegroups.com To
unsubscribe from this group, send email to
coldbox-u...@googlegroups.com
For more options, visit this group at
http://groups-beta.google.com/group/coldbox
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org


Reply all
Reply to author
Forward
0 new messages