Skip to main content
Inspiring
December 20, 2006
Answered

getting images to NOT appear when field in recordset is has content

  • December 20, 2006
  • 3 replies
  • 397 views
On one of my site pages, i have the latest news being pulled in, but i only want the latest news story pulled in if the image field in tbNews contains text. if there is no image then i just want 3 images (these can be hard coded) to be displayed.


DynamicImage is image being pulled in from the image field in tbNews. Image1, image2 and image3 are the images i wanted displayed if the image field in tbNews is empty. If the image field contains text then i do not want Image1, image2 and image3 to be displayed.

****CODE****
<div id="Video"> <img src="uploaded_images/files/news/<cfoutput>#rsLatestNews.image#</cfoutput>" alt="Latest News" name="DynamicImage" id="DynamicImage"> </a> <img src="images/dvdNoFlash.jpg" alt="other images" name="image1" width="87" height="92" id="image1" /><img src="images/dvdNoFlash.jpg" alt="other images" name="image2" width="87" height="92" id="image2" /><img src="images/dvdNoFlash.jpg" alt="other images" name="image3" width="87" height="92" id="image3" /> </div>

RECORDSET:
<cfquery name="rsLatestNews" datasource="DSNGrid">
SELECT *
FROM tbNews
ORDER BY newsDate DESC

the structure for tbNews
newsID
newsDate
newsSubject
newsStory
image

Hope im making sense,

Does anyone know how i achieve this?
    This topic has been closed for replies.
    Correct answer Kamesh192
    Hi

    Dont worry about this, i used another piece of code and it works correclty. But thanks for your help.

    i used <cfif rsLatestNews.image EQ "">...... </cfif>.

    thanks

    3 replies

    Kamesh192AuthorCorrect answer
    Inspiring
    December 21, 2006
    Hi

    Dont worry about this, i used another piece of code and it works correclty. But thanks for your help.

    i used <cfif rsLatestNews.image EQ "">...... </cfif>.

    thanks
    Kamesh192Author
    Inspiring
    December 21, 2006
    Hi

    thanks for you reply, and thanks for the explanation. I copy and pasted your code into my page and for some reason the three static images are being repeated, several times. The page can be viewed at http://www.greengrid.co.uk/mainN.cfm.

    Am i using your code correctly?

    thanks
    Inspiring
    December 21, 2006
    try this:

    <cfoutput query="rsLatestNews">
    <cfif len(trim(rsLatestNews.image)) gt 0>
    <div id="Video"> <img src="uploaded_images/files/news/#rsLatestNews.image#" alt="Latest News" name="DynamicImage" id="DynamicImage"></div>
    <cfelse>
    <div id="Video"><img src="images/dvdNoFlash.jpg" alt="other images" name="image1" width="87" height="92" id="image1" /><img src="images/dvdNoFlash.jpg" alt="other images" name="image2" width="87" height="92" id="image2" /><img src="images/dvdNoFlash.jpg" alt="other images" name="image3" width="87" height="92" id="image3" /> </div>
    </cfif>
    </cfoutput>

    you basically check that the length of text in the image field in the recordset is > 0, and if so display a div with that image, otherwise display a div with your 3 static images.

    hope this helps.