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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database code

Status
Not open for further replies.

stevemarsh99

Technical User
Aug 10, 2005
88
GB
I am in dreamweaver and am trying to get some code to work that says:

If the field in the database for a specific comun is blank then display something

Else

Display the image!

I do not know the code used for 'if the database field is blank' is!!!

Hope you can help
 
What language?
Is the field going to be blank or Null?

if asp
Code:
<%
if recordset.field("field").value = "" then
display something
else
display image
end if
%>

Cheech


[Peace][Pipe]
 
This is what i have and it displays the FULL string:

<% If MAGAZINE.Fields("BANNER1").Value = "" Then
response.write "Fields are BLANK"
Else

response.write "fields are FULL"
End if %>
 
If the field is null then your comparison won't catch it. Try
Code:
<% If MAGAZINE.Fields("BANNER1").Value & "" = "" Then
response.write "Fields are BLANK"
Else
                
response.write "fields are FULL"
End if  %>

The expression < Fields("BANNER1").Value & "" > forces a null to an empty string, but doesn't affect any other strings

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Try this
Code:
<% 
response.write MAGAZINE.Fields("BANNER1").Value
response.write "<br>"
If MAGAZINE.Fields("BANNER1").Value = "" Then 
response.write "Fields are BLANK"
ElseIf MAGAZINE.Fields("BANNER1").Value = NULL
response.write "Fields are BLANK"
Else
response.write "fields are FULL"
End if  %>

Also I thrown in a response write of the field value just to make sure you are getting what you expect whilst testing

[Peace][Pipe]
 
Thanks brilliant guys, it works by simply adding the & ""

Thanks again!
 
Guys i get a problem when I throw a img placeholder in the else section:

<% If MAGAZINE.Fields("BANNER1").Value & "" = "" Then
response.write "Fields are BLANK"
Else


<img src="<%=(MAGAZINE.Fields.Item("BANNER1").Value)%>">
End if %>
 
You're missing the response.write

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
No I need an image to display IF the field is not blank
 
What johnwm meant was that you are not writing the code to the page but including it in your asp code.
Code:
You could use
<% 
If MAGAZINE.Fields("BANNER1").Value & "" = "" Then 
response.write "Fields are BLANK"
Else 
%>       
<img src="<%=(MAGAZINE.Fields.Item("BANNER1").Value)%>">
<%
End if
%>

or

<% 
If MAGAZINE.Fields("BANNER1").Value & "" = "" Then 
response.write "Fields are BLANK"
Else 
response.write"<img src='" & <%=(MAGAZINE.Fields.Item("BANNER1").Value)%>& "'>"
End if
%>

Cheech


[Peace][Pipe]
 
Thanks guys it seemed that i was getting what needed to be inside the delimiters and what needed to actually be displayed!
 
Guys I have flash and gifs that I would like to appear in the 'Else' statement how would I do this?
 
just paste in the code into the else part of the code.

[Peace][Pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top