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
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
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):
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