How to hide duplicate data that is displayed in a table in php

0

** I explain myself better about the image, what I want is that only "one project per ID" is shown, it should be noted that I do not want to use the instructions "DISTINCT, ORDER BY or TOP", because I occupy the fields defects_project_state.status, defects_project_state.Total to get the percentage of progress, (these fields make the output results repeat themselves), I hope and can help me **

  <div class="container-fluid" id="cabecera">
  <table bgcolor = "#808000" align="center" class="table-responsive">
    <?php
//query utilizado para mostrar los resultados en una tabla
        $sql1 = 'SELECT DISTINCTROW proyecto.IDProyectoSpiraTest, proyecto.NombreProyecto, proyecto.Activo, complemento.Estado, defectos_proyecto_estado.Estatus, defectos_proyecto_estado.Total FROM complemento INNER JOIN defectos_proyecto_estado ON complemento.IDProyectoSpiraTestFK = defectos_proyecto_estado.IDProyectoSpiraTest INNER JOIN proyecto ON complemento.IDProyectoSpiraTestFK = proyecto.IDProyectoSpiraTest WHERE proyecto.Activo = 1 AND complemento.NombreProyecto = proyecto.NombreProyecto';
        if (isset($this->valor)) {
            $sql1 .= " AND proyecto.NombreProyecto LIKE '" . $this->valor . "%'";
        }
        //Limitamos el total de resultados por hoja
        $sql1 .= ' LIMIT ' . (($Pagination->get_page() - 1) * $Total_pagina) . ',' . $Total_pagina;
        $sql = $conexion->query($sql1);
        //devolvemos cada fila del resultado del query
        while ($row = $sql->fetch_object()) {
            ?>
  <td align="left">ID proyecto:<?php echo "$row->IDProyectoSpiraTest"; ?></td>
  <td align="left">Nombre:
  <a href="MostrarTab.php?NombreProyecto=<?php echo urlencode("$row->NombreProyecto"); ?>"><?php echo utf8_encode("$row->NombreProyecto"); ?></a></td>
  <td><?php echo str_replace(1, "Activo", "$row->Activo"); ?></td>
  <td align="left">
  <?php if ($row->Estado == 'Analisis y Diseño de Pruebas') {
                echo "<strong style='color:red'> $row->Estado</strong>";
            } else if ($row->Estado == 'Ejecucion de Pruebas') {
                echo "<strong style='color:#04B404'> $row->Estado</strong>";
            } else if ($row->Estado == 'En Espera de Desarrollo') {
                echo "<strong style='color:#DF7401'> $row->Estado</strong>";
            } else if ($row->Estado == 'En tramite') {
                echo "<strong style='color:blue'> $row->Estado</strong>";
            } else if ($row->Estado == 'Nueva Asignacion') {
                echo "<strong style='color:blue'> $row->Estado</strong>";
            } else if ($row->Estado == 'Suspendido') {
                echo "<strong style='color:#DF0101'> $row->Estado</strong>";
            } else if ($row->Estado == 'Cancelado') {
                echo "<strong style='color:#6E6E6E'> $row->Estado</strong>";
            } else if ($row->Estado == 'Pruebas Terminadas') {
                echo "<strong style='color:#000000'> $row->Estado</strong>";
            }
            $a = $row->Estatus;
            if ($a == 'Closed') {
                $FallasC += $row->Total;
            }
            $FallasD += $row->Total;
            echo $porcentaje = ($FallasC / $FallasD) * 100?>
</td>
    <tr>
      <td colspan="4">
        <div class="container">
          <h2>Progreso</h2>
          <div class="col-sm-8 col-md-10 col-lg-12">
            <div class="progress">
              <div class="progress-bar" role="progressbar" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $porcentaje ?>%">
              10%
              </div>
            </div>
           </div>
        </div>
      </td>
    </tr>
    <?php
}
        ?>
  </table>
</div>
    
asked by Carlos Baez 14.05.2017 в 02:47
source

1 answer

0

You can solve it in SQL or PHP, personally it is easier to solve it in the query than in code but let's see:

$proyecto = [];
...
...
while ($row = $sql->fetch_object()) {
 if(!in_array($row->IDProyectoSpiraTest, $proyecto)){
   ... //aquí estás imprimiendo los datos del proyecto que se imprimen una sola vez.
   $proyecto[] = $row->IDProyectoSpiraTest;
 } else {
   ... //aquí se imprimen los datos que se repiten.
 }
}

First we create an array to save the projects, then in each SQL record we check if this project exists and we print the information we want, when it does not exist then we add the project to the array so that in the next SQL record it already exists.

In Query you can do arithmetic operations or window functions to solve your problem. My recommendation is that you research a bit about that instead of modifying your PHP code that already looks quite complex.

    
answered by 14.05.2017 / 18:13
source