My suggestion is to use Javascript to change the structure by inserting the cells into the lines. In PHP you can insert classes by numbering lines in sequence, from 1 to 10. The table structure would look like the image below, each row in a sequence of linha1
to linha10
:
From this, with Javascript I can join all cells of the lines with the same class. Just insert a script right after the PHP code that builds the table:
<?php
$sql = $mysql->prepare("SELECT id FROM usuarios WHERE status = 0");
$sql->execute();
$sql->bind_result($id);
$sql->store_result();
if($sql->num_rows() == 0){
echo "<tr><td>Sem registros</td></tr>";
} else {
$conta = 1; // inicia variável com valor 1
while ($sql->fetch()) {
if($conta%11 == 0){ // reseta $conta a cada 11 linhas
$conta = 1;
}
$classe = "linha".$conta;
echo "<tr class=". $classe ."> // insere a classe na TR
<td>" . $id . "</td>
</tr>";
$conta++;
}
}
?>
</table>
<script>
var linhas = document.body.querySelectorAll("tr[class*='linha']"); //seleciona todas as linhas da tabela
for(var x=10; x<linhas.length; x++){ // loop a partir da 11ª linha
var cls = linhas[x].className.match(/\d+/)[0]; // pega o número da linha
document.querySelector(".linha"+cls).innerHTML += linhas[x].innerHTML; // insere a TD na respectiva linha
linhas[x].outerHTML = ''; // remove a linha
}
</script>
The result will be what shows the figure below:
A link that might help you: https://stackoverflow.com/questions/17608513/loop-to-populate-html-table-vertically
– aa_sp
With CSS and the "column-Count" property you can easily assemble this structure.
– hugocsl
Hello friend. Managed to solve? see that I posted a solution using Javascript, but someone found it useless and voted negative. If you couldn’t solve it, we can see a solution using only PHP. Just give me a feedback there. Obg!
– Sam