Link to home
Start Free TrialLog in
Avatar of aman0711
aman0711

asked on

Ternary Operation

Hi Experts,

                 I need some help with a ternary conditional statement. I have an HTML table.

                 Right now whenever the data in column 4 is zero, I show Column 3 as N/A.

                 what I want now is,
                 keeping the same condition as it is (N/A when column 4 is zero), whenever the value of column three is more than 0, color the text as red.
                 My current code is below:


         
<table align="left" border="1" cellspacing="1" width="100%">
<tr>
<th>Aspect</th>
<th align="center">Metrics in SLA</th>
<th align="center">Metrics out of SLA</th>
<th align="center">Total metrics</th>
<th align="center">SLA compliance</th>
</tr>
<%
while (rs.next()) {
%>
<tr>
<td><a href="<%=(rs.getString(1))%>"><b><%=rs.getString(1)%></b></a></td>
<%
int totalMetrics = rs.getInt(4);
%>
<td class="tab_2Col"><%=totalMetrics == 0 ? "N/A" : "" + rs.getInt(2)%></td>
<td class="tab_3Col"><%=totalMetrics == 0 ? "N/A" : "" + rs.getInt(3)%></td>
<td class="tab_4Col"><%=totalMetrics == 0 ? "N/A" : "" + totalMetrics%></td>
<td class="tab_5Col"><%=totalMetrics == 0 ? "N/A" : "" + nv.format(rs.getFloat(5)) + "%"%></td>
</tr>
<%
met_in += rs.getInt(2); met_out += rs.getInt(3); met_tot += rs.getInt(4);
}
met_SLA = met_tot == 0 ? 0.0 : ((met_in / met_tot) * 100);
%>
 
<tr>
<td><b>Total</b></td>
<td class="tab_2Col"><%=nf.format(met_in)%></td>
<td class="tab_3Col"><%=nf.format(met_out)%></td>
<td class="tab_4Col"><%=nf.format(met_tot)%></td>
<td class="tab_5Col"><%=nv.format(met_SLA)%>%</td>
</tr>
<%
rs.close();
pstmt.close();
%>
</table>

Open in new window

Avatar of Gibu George
Gibu George
Flag of India image


<td class="tab_2Col" <%=(rs.getInt(2)>0 &&totalMetrics!=0)?"style="color:RED;":""%>  ><%=totalMetrics == 0 ? "N/A" : "" + rs.getInt(2)%></td>

Open in new window

Avatar of aman0711
aman0711

ASKER

Hey Gibu,

                    Its giving me error on this peace of code:

                     "style="color:RED;":""%>
SOLUTION
Avatar of a_b
a_b

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi a_b,
               I am getting the same error with your code as well:

               "style=/"color:RED;/":"

               Multiple annotations found at this line.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Gibu, a_b :-)
Whoops, I got the direction of the slash incorrect. gibu_george has the correct direction of the slash.
Code to be replaced in the question:
<table align="left" border="1" cellspacing="1" width="100%">
<tr>
<th>Asp</th>
<th align="center">Met</th>
<th align="center">Metr</th>
<th align="center">Tot</th>
<th align="center">com</th>
</tr>
<%
while (rs.next()) {
%>
<tr>
<td><a href="<%=(rs.getString(1))%>"><b><%=rs.getString(1)%></b></a></td>
<%
int totalMetrics = rs.getInt(4);
%>
<td class="tab_2Col"><%=totalMetrics == 0 ? "N/A" : "" + rs.getInt(2)%></td>
<td class="tab_3Col"><%=totalMetrics == 0 ? "N/A" : "" + rs.getInt(3)%></td>
<td class="tab_4Col"><%=totalMetrics == 0 ? "N/A" : "" + totalMetrics%></td>
<td class="tab_5Col"><%=totalMetrics == 0 ? "N/A" : "" + nv.format(rs.getFloat(5)) + "%"%></td>
</tr>
<%
met_in += rs.getInt(2); met_out += rs.getInt(3); met_tot += rs.getInt(4);
}
met_SLA = met_tot == 0 ? 0.0 : ((met_in / met_tot) * 100);
%>
 
<tr>
<td><b>Tot</b></td>
<td class="tab_2Col"><%=nf.format(met_in)%></td>
<td class="tab_3Col"><%=nf.format(met_out)%></td>
<td class="tab_4Col"><%=nf.format(met_tot)%></td>
<td class="tab_5Col"><%=nv.format(met_SLA)%>%</td>
</tr>
<%
rs.close();
pstmt.close();
%>
</table>

Open in new window