Created UDF, won't display correct output


I created a UDF to display images that are connected to certain content pieces for a new site.  The udf included with others in one library.  I think that my error is how i am displaying the output (not sure).  

I am testing one image that I inserted through my CMS. The image's associated content has a contentID of 45.  However, I am getting the following error on my test page:

Additional Details: Error Executing Database Query. [Macromedia][SQLServer JDBC Driver][SQLServer]Line 4: Incorrect syntax near '45'.
The error occurred on line 15.

is my error on the test page or is it my udf?  i am using cfmx v. 6.1.  should I use cfset??

I am also using a udf for my content.  the content in this case also has an id if 45, but is pulled from a separate udf.  it is currently only dislaying the title for the udf.  how can i display other variables as well (that are actually in my udf)?

should I use var somewhere????

===UDF for Image====
      <!--- Display Image UDF --->
<cffunction name="GetImage">
      <cfargument name="ContentID" type="numeric" required="true">
      <!--- <cfargument name="ImageID" type="numeric" required="true"> --->

      <!--- Get the appropriate image for selected content piece --->      
      <cfquery name="showImage" datasource="#request.dsn#">
            SELECT * FROM PImages
            INNER JOIN PImageParts
            ON PImages.ImageID=PImageParts.ImageID
            WHERE #ARGUMENTS.ContentID#      
      <!--- Return the Image for that Content Area --->      
      <CFRETURN imageName>

===UDF for Content===
<!--- Display Content --->
<cffunction name="GetContent">
      <cfargument name="ContentID" type="numeric" required="true">
<!--- Get Content --->
      <cfquery name="selectContent" datasource="#request.dsn#">
            SELECT * FROM PContent
            INNER JOIN PContentParts
            ON PContent.ContentID=PContentParts.ContentID
            INNER JOIN PCategories
            ON PContentParts.CategoryID=PCategories.CategoryID
            WHERE GETDATE() BETWEEN PContent.startDate and PContent.expireDate
            AND PContent.ContentID=#ARGUMENTS.ContentID#
      <!--- Return the relevant content piece --->
      <cfreturn selectContent.Title>
      <cfreturn selectContent.body>
<span class="header"><cfoutput>#GetContent(45)#</cfoutput></span>

This is a test for fellow kickball teams.
<cfoutput><img src=""></cfoutput>
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


you cant have 2 cfReturns.  You will need to concatinate the 2 pieces of data before you return.

<cfreturn "#getContent.Title#<br>#getContent.body#">

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

also your query needs help.

  <cfquery name="showImage" datasource="#request.dsn#">
          SELECT * FROM PImages
          INNER JOIN PImageParts
          ON PImages.ImageID=PImageParts.ImageID
          WHERE = #ARGUMENTS.ContentID#    
synergeticsoulAuthor Commented:

contentID is a field within PImagesParts, not PImages.  I don't understand why I need to write: WHERE = #ARGUMENTS.ContentID# .  Please clarify.

also, i thought i a few cfreturns were fine?  if not, is there a way that I could also format them output from the udf?  the title has a different style than the actual text.

last, this is still pretty confusing as to why I can't display the image.
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

synergeticsoulAuthor Commented: to the content, are the cfreturns necessary?  can i output the udf and display the necessary fields:

<span class="header"><cfoutput>#GetContent(45)#

ohh...and I am still receiving an error with the content: Additional Details: Element TITLE is undefined in GETCONTENT.
The error occurred on line 38.

<cfquery name="showImage" datasource="#request.dsn#">
          SELECT * FROM PImages
                        INNER JOIN PImageParts ON PImages.ImageID=PImageParts.ImageID
          WHERE PImageParts.contentId = #ARGUMENTS.ContentID#    

synergeticsoulAuthor Commented:
ohh..yeah..i had updated my query to this after my last reply, but i still get the same results for an actual display

on the test page:  

<img src=""></cfoutput>

This may not be written correctly, but I need to display the image associated with contentID 45 (which is fine in my database)

also, i can not display anything other than title, i tried  <cfreturn "#getContent.Title#<br>#getContent.body#"> and it did not work.  where am a erring???

synergeticsoulAuthor Commented:
okay...the image is coming out now....

it was my output too...

<img src=""></cfoutput>

however, i am only getting the title field for my content....

is there another way to add multiple entries?

<cfreturn "#getContent.Title# testing the <br>return. line 1 #getContent.body# after the body">
synergeticsoulAuthor Commented:
is this being placed within my udf?  it's still causing an error.

also, should i place "var" in my function?  my page is displaying quite strangely.  actually, the footer, which is comprised of images, is now displaying in the wrong place.  could this be because my function is still "on"?

yes, try that cfreturn in your getContent function. if it still errors, post the error
synergeticsoulAuthor Commented:
Here's the error:

Additional Details: Element TITLE is undefined in GETCONTENT.
The error occurred on line 38.

Title is a valid variable in my table as well as body.


getContent is the function.... selectContent is the query.

<cfreturn "#selectContent.Title# testing the <br>return. line 1 #selectContent.body# after the body">
synergeticsoulAuthor Commented:
right.  duh.. there a way to format the contents as well.  like using span, div, etc. for the title, separate from the body?

remove the span tags from where you call the UDF and format the output as you return it.

<cfreturn "<span class='header'>#selectContent.Title#</span><br>#selectContent.body#">
synergeticsoulAuthor Commented:
Thank you!!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.