Organizing information in table

Asked

Viewed 33 times

2

I am creating the following table:

<div class="div1" id="employee_table">  
    <table class="table table-bordered">  
        <tr> 
            <th width="10%">De</th>
            <th width="10%">Assunto</th>
            <th width="10%">Prioridade</th>
            <th width="10%">Recebido</th>               
        </tr>
        <tr>
        <th width="10%" colspan=4>Recebido:</th>
        </tr>
                <?php  
            while($row = mysqli_fetch_array($result))  
        {  
        ?>  
        <tr>  
            <td><?php echo $row["De"]; ?></td> 
            <td><?php echo $row["Conteudo"]; ?></td>  
            <td><?php echo $row["Prioridade"]; ?></td> 
            <td><?php echo $row["Hora"]; ?></td>
            <td><?php echo $row["Data"]; ?></td>
        </tr>
        <tr>
        <?php  
        }  
        ?> 
    </table>  
</div>

But the date is not in front of the column Recebido: with colspan =4, as shown in the image:

inserir a descrição da imagem aqui

I meant for you to show up like this:

inserir a descrição da imagem aqui

2 answers

2

I think your problem is with the organization of TH/TD

From what I understand Received and Date has to stay within the same TR and date with colspan 3 since the first cell is Received, see

td, th {
  border: 1px solid #000;
}
<div class="div1" id="employee_table">  
    <table class="table table-bordered">  
        <tr> 
            <th width="10%">De</th>
            <th width="10%">Assunto</th>
            <th width="10%">Prioridade</th>
            <th width="10%">Recebido</th>               
        </tr>

        <tr>
            <th width="10%" >Recebido:</th>
            <th colspan="3">?php echo $row["Data"]; ?></th>
        </tr>

        <tr>  
            <td>?php echo $row["De"]; ?></td> 
            <td>?php echo $row["Conteudo"]; ?></td>  
            <td>?php echo $row["Prioridade"]; ?></td> 
            <td>?php echo $row["Hora"]; ?></td>
        </tr>

    </table>  
</div>

1


One way would be to eliminate the td date and place the date after the string "Received:", by placing the th within the while and conditioning the impression of th whenever a different name comes up. Just put a if and assign the name to a variable, thus:

<div class="div1" id="employee_table">  
   <table class="table table-bordered">  
      <tr> 
         <th width="10%">De</th>
         <th width="10%">Assunto</th>
         <th width="10%">Prioridade</th>
         <th width="10%">Recebido</th>               
      </tr>
      <tr>
      <?php
      while($row = mysqli_fetch_array($result))  
      {
         if($nomede != $row["De"]){
      ?>  
         <th width="10%" colspan=4>Recebido: <?php echo $row["Data"]; ?></th>
      <?php
            $nomede = $row["De"];
         }
      ?>
      </tr>
      <tr>  
         <td><?php echo $row["De"]; ?></td> 
         <td><?php echo $row["Conteudo"]; ?></td>  
         <td><?php echo $row["Prioridade"]; ?></td> 
         <td><?php echo $row["Hora"]; ?></td>
      </tr>
      <?php  
      }  
      ?> 
   </table>  
</div>

The result will be as below:

inserir a descrição da imagem aqui

  • After analyzing very interesting how to return the data this way. I will choose this suggestion

Browser other questions tagged

You are not signed in. Login or sign up in order to post.