Ask a Question related to Coldfusion Database Access, Design and Development.
-
vernade #1
Access a specific resultset (Query) row
I am iterating over a CF Query and want to implement a generic function which
takes the query and the rownumber as a parameter. How can I access a specific
row in a CF Query Object and retrieve the complete row as struct?
Are there any functions on CF Query objects which I can access.
A requirement is that I do not change the cursor (CurrentRow) while iterating
over the query and retrieving the data.
vernade Guest
-
#6503 [Asn->Opn]: no support for multiple resultset query?
ID: 6503 Updated by: tony2001@php.net Reported By: alonso at computacionlegal dot com -Status: Assigned +Status: Open Bug... -
#6503 [Opn->Asn]: no support for multiple resultset query?
ID: 6503 Updated by: bjori@php.net Reported By: alonso at computacionlegal dot com -Status: Open +Status: Assigned Bug Type:... -
return query resultset from custom tag
Hi, How to return an entire query resultset from custom tag to the calling page ? Thanks for your help. vmrao -
Getting recordcount from resultset of 'union' query
Hi, I need to find out the number of records in the resultset of a union of 2 queries. E.g. "select ID from Pages where numPageCatID = " &... -
web services problem processing embedded query resultset
We ran into an interesting problem with using queries and web services. This was on MX 6.1 Windows. This may be known already, though we didn't find... -
mxstu #2
Re: Access a specific resultset (Query) row
As far as I know there are no CF functions that return an entire query row as a
structure, but you can create your own function. Just pass in a query object
and a row number and the function uses the query.columnList to add the column
values for the current row to the returned structure.
<!--- return selected query row as a structure --->
<cfscript>
function GetQueryRow(query, rowNumber) {
var i = 0;
var rowData = StructNew();
var cols = ListToArray(query.columnList);
for (i = 1; i lte ArrayLen(cols); i = i + 1) {
rowData[cols[i]] = query[cols[i]][rowNumber];
}
return rowData;
}
</cfscript>
<cfoutput query="yourQuery">
<cfset theCurrentRow = GetQueryRow(yourQuery, currentRow)>
<cfdump var="#theCurrentRow#">
</cfoutput>
mxstu Guest
-
vernade #3
Re: Access a specific resultset (Query) row
Thank you for your response... this was exactly the solution I was looking for.
I did not realize that you can access a query object with brackets, like
query[column][row].
The CF documentation either misses this point or I was not able to find it.
vernade Guest
-
Rachel #4
Re: Access a specific resultset (Query) row
You can use a query of a query to do this too:
<cfquery name="myQueryRow" dbtype="query">
SELECT * FROM myOtherQuery WHERE id=id_of_row
</cfquery>
Then myQueryRow will only have the row you're selecting, as a query object of its own.Rachel Guest
-
Matt #5
Re: Access a specific resultset (Query) row
I tried several approaches, none of them worked for me except this one:
queryName.field_name[rowNumber]
Can use the queryName.currentrow property to get the current row number and then just add one to it to get your rowNumberMatt Guest



Reply With Quote

