Forum Moderators: open

Message Too Old, No Replies

How to avoid broken image icons?

When there's no image in the database

         

dickbaker

12:25 am on Feb 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm working on a site where I want a little star to appear next to the names of businesses that are subsribers to the site. If they're not, I'd like to have that area blank.

I created a field in the database called "star" and put the star.gif into the field if the business is a subscriber. Otherwise it's blank (or null).

Problem is, when I view the list of businesses, those without the star.gif in the database have a broken image icon next to their names.

Is there any way to have no icon show up at all for those?

Working in SQL server and ASP.

Thanks for any replies.

defanjos

1:03 am on Feb 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I were you, I would do it a bit differently. I would have a field called "subscriber", then have it be true/false or yes/no, then simply show/hide the image like:

<%if rs("subscriber")= true then%><img src="star.gif"><%end if%>

sean

1:15 am on Feb 10, 2004 (gmt 0)

10+ Year Member



If I understand you correctly, you could also have a clear.gif

dickbaker

11:37 pm on Feb 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



defanjos, thanks for the idea. If you wouldn't mind, could you elaborate on that ASP statement, or at least point me to a site where I could figure out the correct syntax? That sounds like an elegant solution.

Thanks,
Dick

defanjos

12:05 am on Feb 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dick,

How are you listing the businesses on the page - aren't you using a recordset?
How are you retrieving the info from the database?

dickbaker

4:19 am on Feb 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, again, defanjos. Thanks for your continued interest in my problem.

Yes, I'm using a a recordset. The businesses are retrieved from the database by having users first go to a particular page that lists states, and then click on that state. The state links are absolute, not dynamic. The state's page SQL statement uses "WHERE state="California," for example, to then show all of the businesses in California that are in the database.

From there, the "star" field is a link that passes the recordset ID on to the detail page as an URL parameter.

Ideally, since the business owners will be the ones who are updating their own records, I'd like to leave the "star" field null. If the business owners are paid subscribers, I'd like to be able to have the "star.gif" image link entered into the "star" field. And if the "star" field is null, I'd like to have no broken image icon appear on the state pages.

There are other fields within the recordset where the business owners can upload images, and the links to them would be inserted into the appropriate fields.

The notion of having a default "clear.gif" value in the image fields might work, but it would entail having to tell the business owners to first delete that file name from the field before entering their own image file names. And there's lots of people out there who won't understand how to highlight and delete a file name before entering their own.

So, an ASP statement that would return no <img src=" "> for null values, and a <img src="my_image.gif"> for a field with a value is what I think I need.

I'm in a bit over my head with this particular ASP statement problem, but I want the site to look absolutely professional. If you have a quick solution, I'd greatly appreciate hearing it. If your solution involves more time than you're willing to give away, PM me about cost. I have to get this site up and running 100% in just a matter of weeks, and this particular lack of knowledge on my part could delay the process indefinitely.

Here's an example of how one of the fields is displayed: <%=(Recordset1.Fields.Item("shopname").Value)%> This is, of course, from Dreamweaver.

And, I should probably add that I work primarily on a Mac. Enough said? ;)

Thanks again for your interest and help.

Dick

defanjos

3:32 pm on Feb 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dick,

From there, the "star" field is a link that passes the recordset ID on to the detail page as an URL parameter.

Can you elaborate on this, I don't quite understand what the "star" field has to do with passing the variables.

Do you have the image (star.gif) stored in the database or just the file name?

I still think you should have a field called "subscribers" instead of "star". This way you can use that info to do other things in the future, for example, you may want to show or hide different things if they are a subscriber or not.

dickbaker

6:13 am on Feb 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks again for your reply, defanjos.

The "star" field is essentially a "subscriber" field. If the business is not a paid subscriber, they don't get a star.gif file name in the "star" field. (Yes, the star.gif is just the filename, not an actual image file).

I've looked at all sorts of ASP statements that use things like

<%if IsNull(Page_A.Fields.Item("star").Value) = False then %>
<%=(Page_A.Fields.Item("star").Value)%>
<br>
<%end if%>

or other variants of that kind of statement. Unfortunately, none have worked.

It's been over a year since I took classes in ASP and, just like learning a foreign spoken language, if you don't use it you lose it.

Thanks again,
Dick

defanjos

3:10 pm on Feb 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to keep that field, you can do it this way:

<%if (Recordset1.Fields.Item("star").Value)="star.gif" then%><img src="star.gif"><%end if%>

This will show a star when the field has "star.gif" in it

btw, you can add height, width and alt to <img src="star.gif">

dickbaker

4:18 am on Feb 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, again, defanjos. Thanks for all your replies.

Because I need to get this going quickly, I had someone at my hosting company tweak the code.

This is what he/she came up with, and it works:

<tr>
<td>
<%if Trim(Recordset1.Fields.Item("star").Value) <> "" then %>
<A HREF="bytownresults.asp?<%= MM_keepURL & MM_joinChar(MM_keepURL) & "ID=" & Recordset1.Fields.Item("ID").Value %>"><img src="<%=(Recordset1.Fields.Item("star").Value)%>" border="0"></A>
<%else%>
<img src="star2.gif">
<%end if%>
</td>
<td class="mysite2"><%=(Recordset1.Fields.Item("shopname").Value)%></td>
<td class="mysite2"><%=(Recordset1.Fields.Item("city").Value)%></td>
<td class="mysite2"><%=(Recordset1.Fields.Item("phone").Value)%></td>
</tr>

This is so close to what you'd suggested that I feel bad for having paid $50 to have one of the ISP techs tweak the code. But paying that $50 saved me hours of aggravation and delay.

I hope that someone else will be able to use this in the future.

Dick