views:

580

answers:

2

I have an if..else statement that will display whether or not the student is qualified to go for competition based from the value in database. But, my code is not working correctly.

My code is as follows:

<% If (rs_view.Fields.Item("StudentStatus").Value="OK") Then %>
<strong><font color="#3300FF" size="-1" face="Arial, Helvetica, sans-serif">
<%Response.Write("You are QUALIFIED to go for competition")%>
</font></strong>

<% Else %>

<strong><font color="#FF0000" size="-1" face="Arial, Helvetica, sans-serif">
<%Response.Write("You are NOT QUALIFIED to go for competition")%>
</font></strong>

<% End If %>

Any ideas?

  • it doesn't work correctly..meaning either the student is qualified or not qualified, it will still display NOT QUALIFIED for both status.
+4  A: 

Perhaps the StudentStatus field in your recordset is lowercase? Wrap it in a UCase()?

Also, you can really simplify that code for readability...

<%
Dim RspMsg, RspColor
If (UCase(rs_view("StudentStatus"))="OK") Then 
    RspMsg = "You are QUALIFIED to go for competition"
    RspColor = "#3300FF"
Else
    RspMsg = "You are NOT QUALIFIED to go for competition"
    RspColor = "#FF0000"
End If

%>

<strong><font color="<%=RspColor%>" size="-1" face="Arial, Helvetica, sans-serif">
<%=QualificationResponse%></font></strong>
CptSkippy
Thanks..I have tried using your codes..but it seems doesn't work correctly..meaning either the student is qualified or not qualified, it will still display NOT QUALIFIED for both status..any other method? Pls help..thank you..
It sounds like your StudentStatus never equals "OK", you should try outputting the value of StudentStatus to see what it actually is. Generally it's a bad idea to make status columns character data as you're discovering. Making StudentStatus a foreign key reference into a Status table would constrain the possible values of StudentStatus and resolve any ambiguity.
CptSkippy
Can you teach me on how to do this?Making StudentStatus a foreign key reference into a Status table would constrain the possible values of StudentStatus
Hi there, How about if I want to save the result either qualified or not qualified direct into database?
+1  A: 

You have loads of redudant code.. this code does the same as yours, but a bit reduced. You should also move the styling into a stylesheet.

<%
If rs_view("StudentStatus") & "" = "OK" Then
  %><strong><font color="#30f" size="-1" face="Arial, Helvetica, sans-serif">You are QUALIFIED to go for competition</font></strong><%
Else
  %><strong><font color="#f00" size="-1" face="Arial, Helvetica, sans-serif">You are NOT QUALIFIED to go for competition</font></strong><%
End If
%>

Now, StudentStatus is simply not OK. What you need to do is ouput StudentStatus and see what it is, e.g. insert the following before or after the code in your question (or the reduced variant above) and check it's output:

<%
Response.Write "*" & Server.HTMLEncode(rs_view("StudentStatus")) & "*"
%>

Possible causes is that the OK is in small caps, it's padded by spaces or isn't OK at all, but instead 1 or true or whatever.

svinto
Thanks..I have tried using your codes..but it seems doesn't work correctly..meaning either the student is qualified or not qualified, it will still display NOT QUALIFIED for both status..any other method? Pls help..thank you..
Did you insert the second code snippet into your code? What does it say between the stars when you're viewing a student that should display as qualified?
svinto
Yes, I do insert the codes..It will display the value in database which is "NOTOK" eventhough the actual value is "OK"
If it displays *NOTOK*, then that's what's in the database for that row. Change the if-statement to whatever is outputted between * and it will start working.
svinto
I'm sorry..what i mean is that the value in database is OK but after execute your codes, the output is NOTOK which is NOT QUALIFIED..it doesn't work correctly...
No one's code, not even the code you posted for us, makes reference to "NOTOK". "NOTOK" appears to be the value in your database.
CptSkippy
If the output is *NOTOK*, then that is the value. If you don't see that value in the database, you are looking at the wrong database/table/row.
svinto
Hi there,How about if I want to save the result either qualified or not qualified direct into database?