Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Images
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

GBurch
Junior Member

United Kingdom
107 Posts

Posted - 09 June 2001 :  05:12:49  Show Profile
I have a large database of users, and I'm using this code to display their images
<img src="../History/<% = oRs("FirstName")%><% = oRs("Surname")%>.gif">

However, not all users have an image, so is there any way to get this code to only display the image if it exists, and to display a placeholder if not?

Please note: the page is written in JScript, so any suggestions written in VBScript are no use to me.

Thanks in advance


http://www.captgb.dabsol.co.uk
http://www.slipstreamservices.com


Edited by - GBurch on 09 June 2001 07:47:07

redbrad0
Advanced Member

USA
3725 Posts

Posted - 09 June 2001 :  08:17:54  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message

<%
strFirstName = oRs("FirstName")
strSureName = oRs("Surname")
strFileName = strFirstName & strSureName & ".gif"

' now check to see if the filename is their
set FSO = Server.CreateObject("Scripting.FileSystemObject")
destfile = "c:\mywebsite/address/html/" & strFileName
If FSO.FileExists(strFileName) Then
Response.Write "<img src=""../History/" & strFileName & """>"
Else
' File Does not exist
Response.Write "no image"
End If
%>


Brad
Go to Top of Page

GBurch
Junior Member

United Kingdom
107 Posts

Posted - 09 June 2001 :  12:06:40  Show Profile
quote:


<%
strFirstName = oRs("FirstName")
strSureName = oRs("Surname")
strFileName = strFirstName & strSureName & ".gif"

' now check to see if the filename is their
set FSO = Server.CreateObject("Scripting.FileSystemObject")
destfile = "c:\mywebsite/address/html/" & strFileName
If FSO.FileExists(strFileName) Then
Response.Write "<img src=""../History/" & strFileName & """>"
Else
' File Does not exist
Response.Write "no image"
End If
%>



That is definately VBScript, not JScript

http://www.captgb.dabsol.co.uk
http://www.slipstreamservices.com


Edited by - GBurch on 09 June 2001 12:07:38
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 09 June 2001 :  14:53:01  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
it sure looks like you are using vbscript

Brad
Go to Top of Page

Phantom007
Starting Member

3 Posts

Posted - 09 June 2001 :  15:12:29  Show Profile
Yep that is vb script alright,
btw instead of
If FSO.FileExists(strFileName) Then Response.Write "<img src=""../History/" & strFileName & """>"Else ' File Does not exist Response.Write "no image"End If
I would use a variable like
If Not oRs.EOF Then
UserImg = oRs("ImageName")
Else
UserImg = "NoImage.gif"
End If

'Then add line to the src code
<img src="<%=UserImg%>">

I find that this is better if your going
to use the image more than once less trips to the database if you are going to just display once then the above is good.

Phantom

Go to Top of Page

Phantom007
Starting Member

3 Posts

Posted - 09 June 2001 :  15:19:23  Show Profile
GBurch,
If you are using JScript then it will still work similar but if you are using JScript you will need to set a variable then just check to see if it is NULL if so then just say something to the effect of

if ImageVariable == NULL{
ImageVariable = 'NoImage.gif' //or what ever you want to do with it.
}
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.31 seconds. Powered By: Snitz Forums 2000 Version 3.4.07