Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

blank field

Status
Not open for further replies.

JohannIcon

Programmer
Sep 3, 2002
440
0
0
MT
Dear All,

I have a table with a number of fields and in one of them, I can store an image.

What I want is if this field does not have any entries, ie it is blank, then I display a common image, whereas if the user enters an image name, I display that image.

At the moment I am doing this:-

'*** Create a recordset to retreive all the editorials from the database
Set rs=Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = dbcon

sql= "SELECT * FROM Editorjal WHERE EditorjalID =" & id

rs.Open (sql)
image = rs("editorjalPic")

<%
if image=&quot;&quot; then
response.Write(&quot;blank&quot;)
%>
<img src=&quot;images/editorjal/editorjal_writing.jpg&quot; width=&quot;175&quot; height=&quot;175&quot; align=&quot;right&quot;>
<%
else
response.Write(&quot;not blank&quot;)
%>
<img src=&quot;images/editorjal/<%=image%>&quot; width=&quot;175&quot; height=&quot;175&quot; align=&quot;right&quot;>
<%
end if
%>

However, the response.write is always &quot;not blank&quot; even if there is no image name in the field.

How can i go around this?

Thanks for your help
 
You better check if the image has some value instead for being empty (editorjalPic field = Null).

<%
image = CStr(rs(&quot;editorjalPic&quot;))

If Len(image) > 0 Then
response.Write(&quot;not blank&quot;)
%>
<img src=&quot;images/editorjal/<%=image%>&quot; width=&quot;175&quot; height=&quot;175&quot; align=&quot;right&quot;>
<%
Else
response.Write(&quot;blank&quot;)
%>
<img src=&quot;images/editorjal/editorjal_writing.jpg&quot; width=&quot;175&quot; height=&quot;175&quot; align=&quot;right&quot;>
<%
End If
%>
 
Thanks

I solved it like this:-

rs.Open (sql)
image = rs(&quot;editorjalPic&quot;)

if image <> &quot;&quot; then
else
image = &quot;editorjal_writing.jpg&quot;
end if
 
One correction to a previous post, isEmpty does not check for a null value in a variable. There are actually three very similar states in VBScript, null, nothing, and empty.
Empty means a variable has been declared but never assigned a value. It is actually possible to assign a variable empty in order to pretend it has never been used.

Code:
Dim a
Response.Write &quot;1: &quot; & isEmpty(a) 'outputs true
a = 1
Response.Write &quot;2: &quot; & isEmpty(a) 'outputs false
a = &quot;&quot;
Response.Write &quot;3: &quot; & isEmpty(a) 'outputs false
a = empty
Response.Write &quot;4: &quot; & isEmpty(a) 'outputs true
-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top