Thanks. On the cfreturn.. What if there are multiple queries? lets say the
queries are

photoInfo
folderInfo
photoDetailInfo

Would I do this?

<cfreturn photoInfo folderInfo photoDetailInfo />

On Thu, Mar 15, 2012 at 4:06 PM, Matthew Woodward <[email protected]>wrote:

> On Thu, Mar 15, 2012 at 1:59 PM, Jason King <[email protected]>wrote:
>
>> Probably not the smartest question, but just want to be sure.
>
>
> No such thing as a dumb question!
>
>
>>
>> Do I need to declare a variable for each value I expect to be returned? I
>> only need a single argument (photo id), but I might have 15 variables
>> returned (photo url, filename, created date, caption, etc). Is this what
>> gets put in the <cfreturn> block?
>
>
> Well you can only return one value from a function with CFRETURN (i.e.
> there is no CFRETURN *block*, it's just <cfreturn myVar /> and that's it),
> so you need to bundle that stuff up in a data container of some sort, be
> that an array, struct, query object, whatever.
>
>
>>
>> For instance, the query would generate a variable of queryName.photo_url.
>> Do I need to set a value of 'getPhoto.photo_url' = queryName.photo_url so
>> that when I want to actually use that value I don't have to use the
>> variable name that the query generated? Does this make sense?
>>
>
> You can return the entire query object if you want. Just be aware for
> thread safety that you need to var scope any variables generated within the
> function, or turn on auto-var scoping in OpenBD.
>
> I don't have any idea about your data, etc. so this may not be exactly
> right but here's the gist of it:
>
> <cffunction name="getPhoto" access="public" output="false"
> returntype="query">
>   <cfargument name="photoID" type="numeric" required="true" />
>
>   <cfset var photoInfo = 0 />
>
>   <cfquery name="photoInfo" datasource="whatever">
>     SELECT * FROM photo WHERE id = <cfqueryparam
> value="#arguments.photoID#" cfsqltype="cf_sql_integer" />
>   </cfquery>
>
>   <cfreturn photoInfo />
> </cffunction>
>
> If you want to return a different datatype change the returntype in the
> opening function tag and obviously get your query data and put that into
> whatever data structure you want to return.
>
> --
> Matthew Woodward
> [email protected]
> http://blog.mattwoodward.com
> identi.ca / Twitter: @mpwoodward
>
> Please do not send me proprietary file formats such as Word, PowerPoint,
> etc. as attachments.
> http://www.gnu.org/philosophy/no-word-attachments.html
>
> --
> online documentation: http://openbd.org/manual/
> google+ hints/tips: https://plus.google.com/115990347459711259462
> http://groups.google.com/group/openbd?hl=en
>

-- 
online documentation: http://openbd.org/manual/
   google+ hints/tips: https://plus.google.com/115990347459711259462
     http://groups.google.com/group/openbd?hl=en

Reply via email to