If the image is not on the image folder show "no image"

Discussion in 'Programming' started by a.ashabi, Aug 20, 2008.

  1. #1
    Hi.I need to show the images wich are in folder images & display "No Image" for those we have not the image in the folder.
    I wrote this code:

    <cfset PhotoLocation =
    "e:\www\NeedBattery\images\manufacturer\<cfoutput>#getBrands.cat_level2_image#</cfoutput>">
    <cfif not FileExists(PhotoLocation)>
    <cfoutput>no image</cfoutput>
    <cfelse>
    <a><img src="#imagePath#images/manufacturer/#getBrands.cat_level2_image#" width="60" height="40" /></a>
    </cfif>

    but the result is incorrect & typed "NO Image" for all the images.
    would u plz help me what is wrong with my code?
    thanks
     
    a.ashabi, Aug 20, 2008 IP
  2. unitedlocalbands

    unitedlocalbands Well-Known Member

    Messages:
    246
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    128
    #2
    If you get this variable
    
    <cfoutput>#getBrands.cat_level2_image#</cfoutput>
    
    Code (markup):
    from a query the you can use a join statment in your query

    like this
    
    <cfquery...
    SELECT COALESCE(cat_level2_image, 'images/nologo.png') AS PictureURL
    </CFQUERY...
    
    Code (markup):
    The you still use the image tag, only you switch that variable to match #pictureurl#
    
    <img src="#imagePath#images/manufacturer/#pictureurl#" width="60" height="40" />
    
    Code (markup):
    That way everytime there is no image in the query it will output a path to a image that says no image. You will need to creat an image that say no image and store it in an image folder.

    Hope this helps
     
    unitedlocalbands, Aug 20, 2008 IP
  3. dshuck

    dshuck Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you take the approach of a "missing image" like unitedlocalbands is explaining, then I would take it a step further and remove ColdFusion from the equation all together. This is something that can be handled 100% on the client side:

    <img src="#yourimage#" width="60" height="40" onerror="this.src='/images/nologo.png';">
    Code (markup):
     
    dshuck, Aug 21, 2008 IP
  4. rcollins

    rcollins Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if you dont like that idea you can do this but im not sure as i would have to have a look at your variables more first

    <cfif isdefined("#getBrands.cat_level2_image#")>
    <a><img src="#imagePath#images/manufacturer#getBrands.cat_level2_image#" width="60" height="40" /></a>
    <cfelse>
    <p>"No image"</p>
    </cfif>

    hope this helps
     
    rcollins, Sep 3, 2008 IP