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

Checking if a DB field has a value 1

Status
Not open for further replies.

d2ned

Programmer
Jun 27, 2003
37
FI
Hi,

I'm struggling with a pretty simple matter.. I'm moving from HTML to ASP completely and I have this free classifieds site, that shows ads as search results from a single database table. The problem is, that some field values can be empty (or null) as in the seller has a cellphone but not a land line number or the product has no photos.

Can I implement a code that firstly checks if a field has a value and then act on it? What I'm doing now is:
Code:
<% objCmd.CommandText = "SELECT * " & _ 
		"FROM ads ORDER BY date" 
	objRst.Open
	While Not objRst.EOF%>

<a href="pics/<%Response.Write objRst("pic1")%>" target="_blank">
              <img src="pics/t_<%Response.Write objRst("pic1thumbnail")%>" width="100" height="70" alt="" border="1"></a>

And so forth, to a total of 4 possible pictures (pic2, pic3 etc..) so I would have to check first if field pic2 has any data in it and only then move on to the picture displaying HTML. Can this be done with a simple IF..THEN logic? I hope my question makes clear what I'm trying to do, it was surprisingly hard to explain :)

-Jim
 
Try this:

<% objCmd.CommandText = "SELECT * " & _
"FROM ads ORDER BY date"
objRst.Open
While Not objRst.EOF%>
If (objRst("pic1"))<>"" Then
<a href="pics/<%Response.Write objRst("pic1")%>" target="_blank">
<img src="pics/t_<%Response.Write objRst("pic1thumbnail")%>" width="100" height="70" alt="" border="1"></a>
End if

-VJ
 
Small Typo:

<% objCmd.CommandText = "SELECT * " & _
"FROM ads ORDER BY date"
objRst.Open
While Not objRst.EOF%>
<%If (objRst("pic1"))<>"" Then%>
<a href="pics/<%Response.Write objRst("pic1")%>" target="_blank">
<img src="pics/t_<%Response.Write objRst("pic1thumbnail")%>" width="100" height="70" alt="" border="1"></a>
<%End if%>

Also you can try something like this:

<% objCmd.CommandText = "SELECT * " & _
"FROM ads ORDER BY date"
objRst.Open
While Not objRst.EOF%>
<%If isnull(objRst("pic1")) Then
Response.Write "No Picture Available"
Else%>

<a href="pics/<%Response.Write objRst("pic1")%>" target="_blank">
<img src="pics/t_<%Response.Write objRst("pic1thumbnail")%>" width="100" height="70" alt="" border="1"></a>
<%End if%>


-VJ

 
Amorous,

I see where you're going with this. I'll try this approach during the weekend!

-Jim
 
Amorous,

your if-then worked perfectly! Thank You for your most valuable help!

-Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top