inserting a default photo

M

MickB Tenerife

Hi
I have an ASP page that calls values from an access database using the DBRW.
One of the fields is a reference to an image file, relative to the specific
record, using the ID field to identify the correct image as below

src="/photos/<%=FP_FieldVal(fp_rs,"ID")%>a.jpg"

If that image does not exist I get the normal "X" image box.
What I would like to do is :
If the image (as above) does not exist then put a default photo
"nophoto.jpg" in its place
thanks for your help
 
R

Ronx

<%
if FP_FieldVal(fp_rs,"ID") = "" Then
%>
<img src="nophoto.jpg" alt="No image available">
<% Else %>
<img src="/photos/<%=FP_FieldVal(fp_rs,"ID")%>a.jpg" alt="">
<% End If %>

Note that FrontPage Design View will display both the nophoto.jpg and a
placeholder for the database image. You should also add width and height
attributes for the images.
--
Ron Symonds
Microsoft MVP (Expression Web)
http://www.rxs-enterprises.org/fp

Reply only to group - emails will be deleted unread.
 
K

Kathleen Anderson

This can be done without script, with a little preplanning. Import the
"nophoto.jpg" into your web site, and prepopulate the database field with
its location. If a real image is available, it will be displayed, otherwise
the "nophoto.jpg" will be displayed.

--

~ Kathleen Anderson
Microsoft MVP - Expression Web
Spider Web Woman Designs
Expression Web Resources: http://www.spiderwebwoman.com/xweb/
Expression Web Wiki: http://expression-web-wiki.com/
FrontPage Resources: http://www.spiderwebwoman.com/resources/
Please reply to the newsgroup for the benefit of others
 
R

Ronx

I think Kathleen's solution requires a field for the image path/name in the
database. With this field, as Kathleen suggested, populate the database with
nophoto.jpg as the default value, or adapt my first post to use this field
instead of the ID field.
Without this field, you will have to check for the presence (or absence) of
the image. The script below should do this:

<%
'Check existence of image
Set fs=Server.CreateObject("Scripting.FileSystemObject")
imgnm = "/photos/" & FP_FieldVal(fp_rs,"ID") & "a.jpg"
imgnm = Server.MapPath(imgnm) 'Find disc filing system location on server
If (fs.FileExists(imgnm))=false Then
'image does not exist
%>
<img src="nophoto.jpg" alt="No image available">
<% Else %>
<img src="/photos/" & FP_FieldVal(fp_rs,"ID") & "a.jpg" alt="">
<% End If
set fs=nothing
%>


--
Ron Symonds
Microsoft MVP (Expression Web)
http://www.rxs-enterprises.org/fp

Reply only to group - emails will be deleted unread.
 
M

MickB Tenerife

Hi Kathleen and Ronx
Thank you for the replies, I allocated a spare field in the database as
suggested and used this to control if the default is displayed or not, just
as you both suggested.
It seeem to be working fine, many thanks for all your help
Mick
 
M

MickB Tenerife

Hi Kathleen for some reason I cant manage to tick the box to say your post
was helpful and a solution to the problem. It does not in any way reflect on
your reply ,which solved the issue, thank you
Mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top