• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

Alternate image if database record is empty

I am building a website with Dreamweaver, ASP/vbscript, and an access database.  I have 3 columns in my database with file paths to images...small, medium, and large.  There are some records that we don't have photos for but plan on getting them.  I would like to know how to make those records show a photo that says "Image Not Available" until we get the correct photo.  Basically, if the image can't be found, it displays the default photo until we upload the correct one.  Can anyone help me out with this?

Scott
0
aswhitehead
Asked:
aswhitehead
  • 5
  • 3
  • 3
  • +2
1 Solution
 
mpalmatiCommented:
Did you try the conditional region?

I'm assuming that if your image is unavailable, the path is absent from the database, and your recordset is empty, call the path of your "unavailable" photo with another rs query.

Select the dynamic image then use the server behavior "Conditional region > Show region if recordset is empty" to call the "unavailable".
0
 
aswhiteheadAuthor Commented:
The way I have set it up is:

The path is in the database for all the photos so the recordset is not empty.  It shows a box with an x in it if the photo is not found.  I have about 60 items that we don't have photos for but we still put the path in the database so that when we upload them they show up automatically.  I would like to have them show a default photo until I upload the missing photos.  How can I make this work?  I am going to try the conditional region but I don't think it will work in this application because the database has a path for the photo...the photo just isn't there.

Scott
0
 
mpalmatiCommented:
The only thing that comes to mind is to save the unavailable image with the path/filename of the missing image, when you get the images in, save over the unavailable with that name?

Since you're saving paths and not images in the database, there's no query you can write to check against a null value.  Are these images being uploaded by clients?  If that were the case, you could leave the db fields null and have them upload the path/filename in the same step as they upload the image to the server.
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
aswhiteheadAuthor Commented:
I found this on the web.  Can anyone tell me if this will do what I want and how to actually use it?  It seems a bit vague.

Question: I need to be able to have an alternate image display if there isnt one present in the record.

Answer:
Hello you , if you record is empty, i think the better way to do that is, make one default valeu to any new Record (in DataBase) in ASP script, you can use a command like this:

<%
if Recordset("imagename") ="default value" then

here you put the src image to be displayed when is default

end if
%>

Im just not sure how to utilize it.

Scott


0
 
webwomanCommented:
I wouldn't put the entire file path in the database -- you don't need to if it's all the same (which it apparently is). You only need the file NAME. Anything that is the same for ALL the images can be generated by the page. Then all you need to do is check that there's something in the field.

Like this...

<% if rs("sm_image")<>"" then %>
   <img src="default_images_path/<%=rs("sm_image")%>">
<%else%>
   <img src="default_image.gif">
<%end if%>

You'd do the same for the other images. If you don't want to display a default image (I just do 'photo not available' as a graphic), you could display text that says the same thing.


0
 
aswhiteheadAuthor Commented:
webwoman,

Your solution worked but only if I delete any reference to the path in the database...basically leave the fields blank for the ones we don't have photos for.  Is there any way for me to leave the filepath in the database but if it doesn't find the photo it is looking for in the images folder, it displays the "photo not available" graphic?

Also,  I have a javascript behavior that is opening the largest photo using the medium rez photo as the link.  It opens in a new window.  Is there any way to apply this to the javascript window?  Below is the code for the popup window.

<td><a href="javascript:;" onMouseUp="MM_openBrWindow('<%=(rsFC.Fields.Item("lg").Value)%>','','toolbar=no,location=no,status=no,menubar=no,width=600,height=600')">

Thanks
Scott
0
 
pdxsurrealCommented:
Personally, I'd go with the idea from mpalmati - just upload the 'No Image Available' image with the expected filename for each record you don't have an image for.  Then when you do get the correct image, overwrite the existing file.

You could also use the FSO to check for the existence of the file listed in the recordset for each record... although I would think that would take a pretty hard performance hit, depending on the number of records you're showing per page.  If the file doesn't exist, use a default image in its place.

As for the pop up 'Full Scale' image, either create a default 'No Image Available' image and upload it in place of each item image (like you would the thumbnails)...  or, if you find out you can use the FSO to check for the file, kill the href tag on the thumbnail if the file doesn't exist.
0
 
webwomanCommented:
You don't need to upload that 'no photo' image multiple times.

If you want to leave the path in the field, check the last 3 characters of the field to see if they're equal to jpg or gif. Or check the field for a period -- if there's no period, there's no filename, right?

I'd have to check the syntax for either of those, but it's certainly not that difficult.
0
 
pdxsurrealCommented:
As I understand it, you already have the path & file name included in each record of your table, even if you don't yet have an actual image of the item?

I agree with webwoman in that it would be a pain to upload that image for each record that doesn't have its own image, but if you want to keep the full path & file name stored in all rows of your table, you'd almost have to - unless you went with the FSO option.
0
 
chriscaputoCommented:
<%

' set u_file to your image, NOTE THIS MUST BE relative
' to your current location.. i.e. ../images/file.gif
u_file=RS.Fields("image")

set fso = createobject("scripting.filesystemobject")

if fso.FileExists (server.mappath(u_file)) then
  Response.Write "<img src=<%=u_file%>"
else
  Response.Write "<img src=default.gif>"
end if

%>

This will check to see if the file exists. You'll need to do that if you specify teh file name by default.  You may need to map your path (i.e. c:\images) to a relative path.  Send me an e-mail if you need instructions to do that.

This way no need to upload a default image.  

-chriscaputo
asp/cf freelance developer
0
 
webwomanCommented:
Do you have the entire path/filename, even if it's not uploaded yet, or JUST the path? It makes a difference.

If the first, you'll need to check to see if the file exists. If the second, you only need to check to see if there's a file extension in the field.

We're throwing out possible solutions for BOTH options, without knowing for sure which one fits your situation.
0
 
aswhiteheadAuthor Commented:
I have the entire path/filename in the database field.  It looks like this:

images/sm_8006-07.jpg

We have actually figured out a workaround by using webwomans suggestion from above and deleting the data from the field in the database entirely if we don't have a photo.  Its not exactly the way we wanted to do it becuase it is more database management but it works.  If we can get a solution to where I can build the database as if we have all the images, and the code figure out if the file actually exists, that would be best.

Thanks
Scott
0
 
pdxsurrealCommented:
Didn't chriscaputo offer the code to check for file existence?
0
 
aswhiteheadAuthor Commented:
I am giving webwoman the points on this one for the best answer in my situtation.

Scott
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 5
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now