PHP:
prepare(\"SELECT * FROM `users`\");
$stmt->execute();
$result = $stmt->get_result();
//
I recommend you check this http://php.net/manual/en/function.array-chunk.php
Example:
$rows = array_chunk($yourArrayfetch, '3'); // 3 = column count;
foreach ($rows as $columns) {
echo "<div class='row'>";
foreach ($columns as $column) {
echo "<div class='column'>$column</div>";
}
echo "</div>";
}
See my inline comments for how my answer works.
Also, you don't really need a prepared statement for your case and you should only include the columns that you intend to use in your SELECT
clause.
Code: (Demo)
$resultset=[
['avatar'=>1,'username'=>'A'],
['avatar'=>2,'username'=>'B'],
['avatar'=>3,'username'=>'C'],
['avatar'=>4,'username'=>'D'],
['avatar'=>5,'username'=>'E'],
['avatar'=>6,'username'=>'F'],
['avatar'=>7,'username'=>'G']
];
if(sizeof($resultset)){ // your num rows
$counter=0; // initialize the counter
foreach($resultset as $row){ // you while loop
if($counter%6==0){ // see if counter is evenly divisible by 6
if($counter){
echo "</div>"; // if counter does not equal zero, close previous group
}
echo "<div class='ui stackable six cards'>"; // start new group
}
echo "<div class='ui card small'>";
echo "<div class='ui card small'><div class='image'><img src='".$row["avatar"]."'></div>";
echo "<div class='content'><a class='header'>Dias".$row["username"]."</a></div></div>";
echo "</div>";
++$counter; // increment counter
}
echo "</div>"; // always close the final group
}
Output:
<div class='ui stackable six cards'>
<div class='ui card small'>
<div class='ui card small'><div class='image'><img src='1'></div>
<div class='content'><a class='header'>DiasA</a></div></div>
</div>
<div class='ui card small'>
<div class='ui card small'><div class='image'><img src='2'></div>
<div class='content'><a class='header'>DiasB</a></div></div>
</div>
<div class='ui card small'>
<div class='ui card small'><div class='image'><img src='3'></div>
<div class='content'><a class='header'>DiasC</a></div></div>
</div>
<div class='ui card small'>
<div class='ui card small'><div class='image'><img src='4'></div>
<div class='content'><a class='header'>DiasD</a></div></div>
</div>
<div class='ui card small'>
<div class='ui card small'><div class='image'><img src='5'></div>
<div class='content'><a class='header'>DiasE</a></div></div>
</div>
<div class='ui card small'>
<div class='ui card small'><div class='image'><img src='6'></div>
<div class='content'><a class='header'>DiasF</a></div></div>
</div>
</div>
<div class='ui stackable six cards'>
<div class='ui card small'>
<div class='ui card small'><div class='image'><img src='7'></div>
<div class='content'><a class='header'>DiasG</a></div></div>
</div>
</div>
I will reference this question since this is what you need: checking if a number is divisible by 6 PHP
Your logic you should basically be: If a number is divisible by 6 then do something otherwise do something else.
if ($row_number % 6 == 0) {
// Row number is 6, 12, 18 and so on
} else {
// Other rows
}