show image if DB field has "FAIL" (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


travismp -> show image if DB field has "FAIL" (5/6/2008 15:25:02)

I have a column in my DB that will say 'Pass' or 'Fail' I also have a results search form online that will show the 'Pass' or 'Fail' from that query.

Instead of showing the text I would rather show an image. A red stop light for 'Fail' and a green stop light for 'Pass'. What do I need to do to the code to say show the button btn_FAIL instead of the text 'Fail'

here is my code now
<td width="33"><font size="1" face="Arial"><%=FP_FieldVal(fp_rs,"PASS")%></font><font size="1" face="Lucida Sans Unicode"> </font> </td>




rdouglass -> RE: show image if DB field has "FAIL" (5/6/2008 15:56:59)

quote:

<%=FP_FieldVal(fp_rs,"PASS")%>


Maybe something like this:

<img src="/images/<%IF lcase(trim(FP_Field(fp_rs,"PASS")&"")) = "pass" Then%>btn_PASS<%Else%>btn_FAIL<%End If%>.jpg">

Assuming they are both .JPG images, this should show either "/images/btn_PASS.jpg" or "/images/btn_FAIL.jpg".

Hope that helps.




travismp -> RE: show image if DB field has "FAIL" (5/6/2008 16:07:54)

Here is my exact code:

<img src="/image/<%IF lcase(trim(FP_Field(fp_rs,"PASS")&"")) = "Fail" Then%>RedDot.jpg<%Else%>GreenDot.jpg<%End If%>">


Right now it does show a the GreenDot.jpg all the way down. It seems to be ignoring the data in the column of "PASS" and just showing the green button.




travismp -> RE: show image if DB field has "FAIL" (5/6/2008 16:12:14)

I took out a few things (and I am not sure why, I just play with the script until it does something and this seems to work

<img src="/image/<%IF FP_Field(fp_rs,"PASS")="FAIL" Then%>RedDot.jpg<%Else%>GreenDot.jpg<%End If%>">


Is there anything wrong with just running this?




rdouglass -> RE: show image if DB field has "FAIL" (5/6/2008 16:16:43)

quote:

Is there anything wrong with just running this?


If it works, it's good code. [;)] I just get into the "lcase" habit sometimes when comparing strings.

PS: You were comparing lcase (lowercase) to "Fail" [;)]




travismp -> RE: show image if DB field has "FAIL" (5/6/2008 16:18:05)

Good I will elave it then. THANK YOU for the help.

What does the "lcase" do? I have never used it. Thanks




Spooky -> RE: show image if DB field has "FAIL" (5/6/2008 16:22:35)

It changes any inputs to lower case.
Some comparisions will fail if the case is different, so it pays to get into the habit.

eg "Fail" is different than "fail" in some functions whereas lcase("Fail") will = "fail"




travismp -> RE: show image if DB field has "FAIL" (5/6/2008 16:25:36)

OK very nice. I will try to use that in the future.

Well thank you both for the help today then. This is a finished project and hopefully someone else will eventually find it helpful. Have a good day.

Travis




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
9.399414E-02