Ir para conteúdo
Fórum Script Brasil
  • 0

Converter resultado de loop while de 6 linha para 6 colunas em PHP


WAT

Pergunta

Tenho dois while onde imprimi o seguinte:
 

//Primeito while
Cod. 100  Produto Carne com osso

//Segundo while
Dt. Fabric    Dt. Val        Lote     Qtde. Cx    Qtde. Peso
25/03/2023    24/03/2024    3           36         720,0
25/03/2023    24/03/2024    4           9         180,0
25/03/2023    24/03/2024    2           105       2.100,0
27/03/2023    26/03/2024    3           55       1.100,0
28/03/2023    27/03/2024    2           6         120,0
28/03/2023    27/03/2024    1           49         980,0

//Primeito while

Cod. 200  Produto Carne sem osso

//Segundo while

Dt. Fabric    Dt. Val        Lote     Qtde. Cx    Qtde. Peso
25/03/2023    24/03/2024    3           36         720,0
25/03/2023    24/03/2024    4           9         180,0
25/03/2023    24/03/2024    2           105       2.100,0
27/03/2023    26/03/2024    3           55       1.100,0
28/03/2023    27/03/2024    2           6         120,0
28/03/2023    27/03/2024    1           49         980,0

 

Gostaria que ficasse assim:


Cod. 100  Produto Carne com osso


Dt. Fabric    Dt. Val        Lote  Qtde. Cx    Qtde. Peso  | Dt. Fabric    Dt. Val        Lote  Qtde. Cx    Qtde. Peso | Dt. Fabric    Dt. Val        Lote  Qtde. Cx    Qtde. Peso
25/03/2023    24/03/2024    3           36         720,0  | 25/03/2023    24/03/2024    4           9         180,0   | 25/03/2023    24/03/2024    2           105       2.100,0
27/03/2023    26/03/2024    3           55       1.100,0  | 28/03/2023    27/03/2024    2           6         120,0    | 28/03/2023    27/03/2024    1           49         980,0 

Cod. 200  Produto Carne sem osso

Dt. Fabric    Dt. Val        Lote  Qtde. Cx    Qtde. Peso  | Dt. Fabric    Dt. Val        Lote  Qtde. Cx    Qtde. Peso | Dt. Fabric    Dt. Val        Lote  Qtde. Cx    Qtde. Peso
25/03/2023    24/03/2024    3           36         720,0  | 25/03/2023    24/03/2024    4           9         180,0   | 25/03/2023    24/03/2024    2           105       2.100,0
27/03/2023    26/03/2024    3           55       1.100,0  | 28/03/2023    27/03/2024    2           6         120,0    | 28/03/2023    27/03/2024    1           49         980,0 

Desde já agradeço!

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0
<!-- mysql 
CREATE TABLE `tbacougue` (
  `id` int NOT NULL AUTO_INCREMENT,
  `cod` int DEFAULT NULL,
  `fab` date DEFAULT NULL,
  `val` date DEFAULT NULL,
  `lote` int DEFAULT NULL,
  `qt` int DEFAULT NULL,
  `peso` float DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci -->

<style> td{text-align:right} </style>
<?php
function fmt($dia){return date('d/m/y',strtotime($dia));}
$mysqli=new mysqli("localhost","root","","astudy");
$query=$mysqli->query("select cod from tbacougue group by cod");
while($row=$query->fetch_assoc()){
$cod=$row['cod'];
echo "Código do produto: $cod";
$subq=$mysqli->query("select * from tbacougue where cod=$cod");
$num_rows=mysqli_num_rows($subq);
echo "<table><th>Fab<th>Val<th>Lote<th>Qt<th>Peso<th>|<th>Fab<th>Val<th>Lote<th>Qt<th>Peso";
for($i=0;$i<$num_rows;$i=$i+2){
    $s=$subq->fetch_array();
    echo "<tr><td>".fmt($s[2])."<td>".fmt($s[3])."<td>".$s[4]."<td>".$s[5]."<td>".$s[6];
    $s=$subq->fetch_array();
    if($s){
        echo "<td>|<td>".fmt($s[2])."<td>".fmt($s[3])."<td>".$s[4]."<td>".$s[5]."<td>".$s[6];}}
echo "<tr></table>";}

 

 

 

Screenshot_1.png

Editado por Frank K Hosaka
Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,9k
×
×
  • Criar Novo...