How to show a row in a SQL query?

1

I have an SQL query in a web application, what I want to show is that the rows with total = 100 are displayed in color verde and rows with total = 0 are displayed in color rojo , but not How to implement this function

Could you help me?

               <%
consulta conexion = new consulta ("jdbc:oracle:thin:@localhost:1521:XE","pasaportes","oppasaportes");
    String consulta = "SELECT id_delegacion, CONTRATO   , prerequisitos_tecnologicos, equipamiento, sistema_operacion, privilegios, capacitacion, citas FROM delegaciones";

   ResultSet rs = conexion.ejeSelect(consulta);
     ResultSetMetaData rsmd = rs.getMetaData();
           int col= rsmd.getColumnCount();           
                 for(int k=1;k<=col;k++){          
            %>                                       
            <td><h9> <%= rsmd.getColumnName(k) %></h9></td>
            <%
                            }      
            %>                               
        </tr>         

        <%
         while(rs.next()){
        %>
        <tr class="info"> 

            <td><h6><%= rs.getString(1) %></h6> </td>
            <td><h6><%= rs.getString(2) %></h6> </td>
            <td><h6><%= rs.getString(3) %></h6> </td>
            <td><h6><%= rs.getString(4) %></h6> </td>
            <td><h6><%= rs.getString(5) %></h6> </td>
            <td><h6><%= rs.getString(6) %></h6> </td>
            <td><h6><%= rs.getString(7) %></h6> </td>
            <td><h6><%= rs.getString(8) %></h6> </td>



        </tr>   
        <%
                   }
        %>
            </table>
   </div>
    
asked by Manny Brenes 22.03.2017 в 17:18
source

2 answers

2

As you said it is a dynamic table, in the program with which you fill your table you put a condition in which you give a class name or an id to the row when the value is = 100 and another when = 0 and then by CSS you give the color you want.

I leave you an example in which the color of the entire row is changed. When the value is zero, the element tr would be like this: <tr id="cero">...</tr> and if it is one hundred it would be <tr id="cien">...</tr> , then, by CSS the color of the whole row is changed simply with this: .info tr#cero { color:red; } , if you only want to change the color of a column, would be with this: .info td#cero { color:red; } and in that case would assign the id="zero" or id="hundred" not to the entire row, but to the specific column you want to change.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tabla</title>
<style type="text/css">
	.info tr, th, td { border: 1px solid black; }

	.info tr#cero { color:red; }

	.info tr#cien {color: green; }


</style>
</head>

<body>
<table class="info">
<!-- Si el valor es cero se asigna un id="cero" a tr -->
    <tr id="cero">
        <td>rs.getString(1) es 0</td>
        <td>rs.getString(2) es 0</td>
        <td>etc... es 0</td>
    </tr>
<!-- Si el valor normal, entonces tr normal -->
    <tr>
        <td>rs.getString(1) no es 0 ni 100</td>
        <td>rs.getString(2) no es 0 ni 100</td>
        <td>etc... no es 0 ni 100</td>
    </tr>
<!-- Si el valor es 100, entonces tr con id=cien -->
    <tr id="cien">
        <td>rs.getString(1) valor es 100</td>
        <td>rs.getString(2) valor es 100</td>
        <td>etc... valor es 100</td>
    </tr>
</table>
</body>
</html>
<html>
    
answered by 23.03.2017 / 00:38
source
1

You can use javascript to go through the table and assign it a color I'll give you an example that you have to adjust a little to your table

<script type="text/javascript">
function cargar() {
    var celdas = document.getElementById("target").getElementsByTagName("td");
    for(var i=0; i<celdas.length; i++) {
        if(celdas.item(i).textContent >=3 && celdas.item(i).textContent <=8) {
            celdas.item(i).style.color = "#F00";
        }
    }
}

window.onload = cargar;
</script>
    
answered by 22.03.2017 в 18:08