Example table
PHP code
$td1="";
$td2="";
$td3="";
$Linha="";
$linhaFim="";
$result="";
$pesoOld="";
$dimensaoOld="";
$dimensaoOld2="";
$z="1";
$link = new mysqli ("localhost", "USUARIO", "SENHA", "NOME_DB");
$sqlm = ("SELECT * FROM dados order by id asc");
$resultado = mysqli_query($link,$sqlm);
echo "<table border=\"1\"><tr><th>Cod.:</th><th>Produto</th><th>Qtd.:</th><th>Un.:</th><th>Volume:</th><th>Peso:</th><th>Dimensao: A.L.C.</th></tr>\n";
while($row = mysqli_fetch_assoc($resultado)) {
$cod=$row["cod"];
$produto=$row["produto"];
$qtd=$row["qtd"];
$un=$row["un"];
$volume=$row["volume"];
$peso=$row["peso"];
$dimensao=$row["dimensao"];
$Linha = "<tr>\n<td>".$cod."</td>\n<td>".$produto."</td>\n<td>".$qtd."</td>\n<td>".$un."</td>\n";
$td1 = "<td>".$volume."</td>\n";
$td2 = "<td class=".$volume.">".$peso."</td>\n";
$td3 = "<td class=".$volume.">".$dimensao."</td>\n";
$linhaFim = "\n</tr>\n";
$result .= $Linha.$td1.$td2.$td3.$linhaFim;
}
$ocorrencias = substr_count($result,"<td>Caixa");
for ($k = 1; $k < $ocorrencias; $k++) {
$num = substr_count($result,"<td>Caixa ".$k."</td>");
if ($num > 1){
$result = preg_replace("#<td>Caixa ".$k."</td>#", "<td rowspan=\"".$num."\">Caixa ".$k."</td>", $result,1);
$result = preg_replace("#<td>Caixa ".$k."</td>#", "", $result,$num-1);
$volume="Caixa ".$k;
$consultar = "SELECT volume,dimensao, peso, SUM(peso) AS subt FROM (SELECT volume,dimensao,peso FROM dados Where volume='$volume' ORDER BY id ASC LIMIT $num) AS tabelaSubt";
$resulta = mysqli_query($link, $consultar);
while($item = mysqli_fetch_assoc($resulta)){
$peso = $item["peso"];
$subt = $item['subt'];
$dimensao = $item['dimensao'];
$volume = $item['volume'];
$dimensaoTot="23 x 54 x 82 cm";
//volume para 2 itens de 23 x 54 x 82 cm
$dimensaoTot2="?? x ?? x ?? cm";
$result = preg_replace("#<td class=".$volume.">".$peso."</td>#", "<td rowspan=\"".$num."\">".$subt." Kg</td>", $result,1);
$result = preg_replace("#<td class=".$volume.">".$peso."</td>#", "", $result,$num-1);
$result = preg_replace("#<td class=".$volume.">".$pesoOld."</td>#", "", $result,$num-1);
$result = preg_replace("#<td class=".$volume.">50 x 43 x 55 cm</td>#", "<td rowspan=\"".$num."\">".$dimensaoTot."</td>", $result,1);
$result = preg_replace("#<td class=".$volume.">50 x 43 x 55 cm</td>#", "", $result,$num-1);
$result = preg_replace("#<td class=".$volume.">".$dimensaoOld."</td>#", "", $result,1);
$result = preg_replace("#<td class=".$volume.">23 x 54 x 82 cm</td>#", "<td rowspan=\"".$num."\">".$dimensaoTot2."</td>", $result,1);
$result = preg_replace("#<td class=".$volume.">23 x 54 x 82 cm</td>#", "", $result,$num-1);
$result = preg_replace("#<td class=".$volume.">".$dimensaoOld2."</td>#", "", $result,1);
$pesoOld=$peso;
$dimensaoOld=$dimensao;
$dimensaoOld2=$dimensao;
}
}
}
echo $result;
echo "</table>";
This is a basic routine that can be incremented according to needs since the question did not give all possible variations
What programming language will you use for that?
– Sergio
php usage friend and mysql
– Samuel
Okay, I added that tag to the question to make it clearer.
– Sergio
You can share the code you already have?
– Sergio
tried to use a distinct com group by no select?
– adventistaam
<? while ($line = mysql_fetch_array($sql_vol)) { ? > <tr> <! -- Start list volume items --> <td width="auto"><? echo $line ['pro_cod'];? ></td> <td width="auto"><? echo $line ['pro_nome'];? ><br><font class="desc"><i><<<? echo $line ['pro_descricao'];? ></i></font></td> <td width="auto"><? echo $line ['vi_quantidade'];? ></td> <td width="auto"><? echo $line ['med_name'];? ></td> <td width="auto" rowspan="""><? echo $line ['vol_name'];? ></td> <td width="auto" rowspan=""><? echo $line ['vol_peso'];? > kg</td>
– Samuel
(SELECT 
produto.pro_cod,
produto.pro_nome,
produto.pro_descricao,
SUM(volume_itens.vi_quantidade) AS vi_quantidade,
medida.med_nome,
volume.vol_id,
volume.vol_nome,
volume.vol_peso,
volume.vol_altura,
volume.vol_largura,
volume.vol_comprimento
FROM volume
LEFT JOIN volume_itens ON volume.vol_id = volume_itens.vi_vol_id
LEFT JOIN produto ON volume_itens.vi_pro_id = produto.pro_id
LEFT JOIN medida ON produto.pro_med_id = medida.med_id
WHERE vol_sai_id = '$id'
GROUP BY pro_id, vol_name ORDER BY vol_name AND pro_name ASC)
– Samuel
I tried but it didn’t work
– Samuel
and as distinct?
– adventistaam
no chance I tried.... in reality it is happening like this
– Samuel
will not already tried.... is pulling the right db information. my priblema and in the game hr on the screen q I want to organize in the picture while pulls 3 resolutions so id, Cod, product, Qtd, un, volume, weight and dimension 1, 10, product 1, 100, Un, box 1, 10kg, 50 x 43 x 55 cm 2, 13, wwww, 1, Un, box 1, 10kg, 50 x 43 x 55 cm 3, 10, product 1, 200, Un, Box 2, 15kg, 23 x 54 x 82 cm .
– Samuel
Can you post the HTML of one of the images to know which style is applied to the table? Class, id etc...
– user60252
The weight of box 1 should not be 20 kg ?
– user60252