?
Solved

Alternate image if database record is empty

Posted on 2003-02-24
14
Medium Priority
?
178 Views
Last Modified: 2008-03-06
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
Comment
Question by:aswhitehead
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +2
14 Comments
 

Expert Comment

by:mpalmati
ID: 8012628
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
 

Author Comment

by:aswhitehead
ID: 8016347
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
 

Expert Comment

by:mpalmati
ID: 8016525
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
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 

Author Comment

by:aswhitehead
ID: 8017039
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
 
LVL 19

Accepted Solution

by:
webwoman earned 200 total points
ID: 8017979
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
 

Author Comment

by:aswhitehead
ID: 8019277
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
 

Expert Comment

by:pdxsurreal
ID: 8020829
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
 
LVL 19

Expert Comment

by:webwoman
ID: 8022422
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
 

Expert Comment

by:pdxsurreal
ID: 8023546
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
 

Expert Comment

by:chriscaputo
ID: 8028993
<%

' 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
 
LVL 19

Expert Comment

by:webwoman
ID: 8029962
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
 

Author Comment

by:aswhitehead
ID: 8033254
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
 

Expert Comment

by:pdxsurreal
ID: 8036180
Didn't chriscaputo offer the code to check for file existence?
0
 

Author Comment

by:aswhitehead
ID: 8720311
I am giving webwoman the points on this one for the best answer in my situtation.

Scott
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month12 days, 10 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question