Reply to topic
CFIF Statement Question
yobri


Joined: 31 Jan 2007
Posts: 4
Reply with quote
I am trying to have an image be displayed if a specified field in the database has data in it. I was looking for a IS NOT BLANK or something to that effect in Cold Fusion but I don't see that it exists. It should be a very easy solution.

I simply want CFIF statement that says if the field has URL data in it that i needs to display the image in the URL otherwise show nothing.

Any criteria with the CFIF to work through this?
Jason101
Forum Regular

Joined: 14 Mar 2006
Posts: 550
Location: Harrisburg, PA
Reply with quote
No Problem..

Lets say your field is called MyQuery.Image

Code:

<cfif Len(MyQuery.Image)>
    <img src="#MyQuery.Image#" />
<cfelse>
   No Image Available
</cfif>


What this does is it checks the length of the data in the field. If it's 0, then it does not display an image. If it's NOT 0 in length, it will display the image.

You could also specify a length:

Code:


<cfif Len(MyQuery.Image) GT 5>
    <img src="#MyQuery.Image#" />
<cfelse>
   No Image Available
</cfif>


Hope this helps
Smile
Solution
yobri


Joined: 31 Jan 2007
Posts: 4
Reply with quote
I was able to find an even simpler solution...lol

<CFIF #img2# EQ"">

that pretty much sums it up...thanks for your reply though.
Re: Solution
Jason101
Forum Regular

Joined: 14 Mar 2006
Posts: 550
Location: Harrisburg, PA
Reply with quote
yobri wrote:
I was able to find an even simpler solution...lol

<CFIF #img2# EQ"">

that pretty much sums it up...thanks for your reply though.


Just a coding tip..Cool

You don't need to use "#" 's within any Coldfusion tags. Only during <cfoutput>
emmet


Joined: 16 Nov 2004
Posts: 27
Reply with quote
Jasons way is correct. In your "simpler" answer you are doing a string comparison which takes longer than testing the length of a string. Its not gonna be noticable difference from the browser side but it is the more efficient way to do it.

-e
CFIF Statement Question
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic