Generate Table with PHP group index

0

How can I make a Table that shows me a Line at the beginning of each Group in a table To understand me better I am putting below an image of how I need

Current Table TableWithIndex

<tableclass="table table-bordered table-condensed table-striped table-primary table-vertical-center checkboxs js-table-sortable">
 <thead>
    <tr>
        <th class="center" style="width: 10px;">Imóvel</th>
        <th style="width: 60px;">Inquilino</th>
        <th style="width: 60px;">Inicio</th>
        <th class="center"style="width: 50px;">Jan</th>
        <th class="center"style="width: 50px;">Fev</th>
        <th class="center"style="width: 50px;">Mar</th>
        <th class="center"style="width: 50px;">Abr</th>
        <th class="center"style="width: 50px;">Mai</th>
        <th class="center" style="width: 50px;">Jun</th>
        <th class="center" style="width: 50px;">Jul</th>
        <th class="center" style="width: 50px;">Ago</th>
        <th class="center" style="width: 50px;">Set</th>
        <th class="center" style="width: 50px;">Out</th>
        <th class="center" style="width: 50px;">Nov</th>
        <th class="center" style="width: 50px;">Dez</th>

    </tr>
</thead>
<tbody>

<?  

$busca = Sanitize::filter($_GET['consulta']);
$coluna = Sanitize::filter($_GET['coluna']);
$ano2 = Sanitize::filter($_GET['ano']); 
$data = Sanitize::filter($_GET['data']);
$status = Sanitize::filter($_GET['status']);
$consulta2 = Sanitize::filter($_GET['consulta']);

$filtro = "YEAR(f.vencimento) = $ano2 AND f.status = '$status' "; 

$sql = "SELECT f.*,i.*,n.*,q.*,

 q.nome AS nomecli,
 n.nome AS nomeimo,
 f.valor AS valor_fixado, 
 f.vencimento AS ven,
 f.status AS sta, 
 f.iptu AS iptuf, 
 f.rateio AS rateiof, 
 f.total AS totalf, 
 f.cb AS cbf FROM finan AS f

           LEFT JOIN imoveis AS i
           ON i.id_unidade = f.id_imovel
           LEFT JOIN nome_imoveis AS n
           ON n.id_imovel_principal = i.id_imovel
           LEFT JOIN inquilino AS q
           ON q.id_cli = i.id_inquilino
 where  YEAR(f.vencimento) = $ano group by f.id_imovel  ORDER by nomeimo ASC, unidade DESC";

 // Executa a consulta
 $query = mysql_query($sql);
 // ============================================
 // Começa a exibição dos resultados

 while ($linha = mysql_fetch_assoc($query)) {

 $id_finan = $linha['id_finan'];
 $nomeimo = $linha['nomeimo'];
 $nomecli = $linha['nomecli'];
 $unidade = $linha['unidade'];
 $id_imovel = $linha['id_unidade'];
 ?>   
<input type="hidden"  name="acao" value="up"  />   
<input type="hidden" name="id" value="<?echo $id?>" />
<tr class="selectable" >
        <td ><?echo $unidade?></td>
        <td class="important"><?echo $nomecli?></td>
        <td class="important"><?echo $start?></td>
        <td class="important"><?echo $jan?></td>
        <td class="important"><?echo $fev?></td>
        <td class="important"><?echo $mar?></td>
        <td class="important"><?echo $abr?></td>
        <td class="important"><?echo $mai?></td>
        <td class="important"><?echo $jun?></td>
        <td class="important"><?echo $jul?></td>
        <td class="important"><?echo $ago?></td>
        <td class="important"><?echo $set?></td>
        <td class="important"><?echo $out?></td>
        <td class="important"><?echo $nov?></td>
        <td class="important"><?echo $dez?></td>
    </tr>
  </table>


  <?}?>
    
asked by anonymous 02.11.2016 / 01:14

1 answer

4

A simple solution is to add the property name to a list and check with in_array() if the drive in question already has a title line, like this:

// Cria uma lista para recolher os nomes dos imóveis
$imoveis = array();

while ($linha = mysql_fetch_assoc($query)) {

    $id_finan = $linha['id_finan'];
    $nomeimo = $linha['nomeimo'];
    $nomecli = $linha['nomecli'];
    $unidade = $linha['unidade'];
    $id_imovel = $linha['id_unidade'];

    // Confere se o nome já está na lista, 
    // se não está, abra uma nova linha com o nome
    if ( ! in_array( $nomeimo, $imoveis ) ) {
        $imoveis[] = $nomeimo;
        ?>
        <tr><td colspan="14"><?php echo $nomeimo; ?></td></tr>
        <?php
    }

    // continua
}
    
02.11.2016 / 01:46