Question
Storing database output in a variable
Hi all!
I cannot find the answer to this question ANYWHERE in any book or on the Internet so here goes!
I want to store the output from a database query into a variable. Thats it! Sounds simple right? Nope, its the hardest thing ever.
This is my query:
<cfquery name="rsProductRange" datasource="01">
SELECT s1.PartNo
FROM dbo.Stage s1
WHERE s1.Manufacturer = 'Acer'
</cfquery>
I want to store the PartNo values into a variable as a single string. So for example, the PartNo outputs would be 54.QJ91K.UC5, 66.QJ02K.UC6, 32.QJ13K.UC7, 49.QJ37K.UC8.
I assumed that to store these values as a string into a variable, I would do this:
<cfset PartNos = <cfoutput query="rsProductRange">#rsProductRange.ManfPartNo# ;</cfoutput> >
but the above doesn't work, because it can't "read" the <cfoutput query> bit onwards and causes errors.
However if I just place <cfoutput query="rsProductRange">#rsProductRange.ManfPartNo# ; </cfoutput> within my HTML code, it outputs perfectly all the part numbers in a list seperated by a semi-colon.
I cannot find the answer to this question ANYWHERE in any book or on the Internet so here goes!
I want to store the output from a database query into a variable. Thats it! Sounds simple right? Nope, its the hardest thing ever.
This is my query:
<cfquery name="rsProductRange" datasource="01">
SELECT s1.PartNo
FROM dbo.Stage s1
WHERE s1.Manufacturer = 'Acer'
</cfquery>
I want to store the PartNo values into a variable as a single string. So for example, the PartNo outputs would be 54.QJ91K.UC5, 66.QJ02K.UC6, 32.QJ13K.UC7, 49.QJ37K.UC8.
I assumed that to store these values as a string into a variable, I would do this:
<cfset PartNos = <cfoutput query="rsProductRange">#rsProductRange.ManfPartNo# ;</cfoutput> >
but the above doesn't work, because it can't "read" the <cfoutput query> bit onwards and causes errors.
However if I just place <cfoutput query="rsProductRange">#rsProductRange.ManfPartNo# ; </cfoutput> within my HTML code, it outputs perfectly all the part numbers in a list seperated by a semi-colon.
