So I have the following code on a page that I *think* should be working to display the data in a grid of 4 columns with 1 row in each column:
Quote:
<?php
$rows = $result->num_rows; // Find total row
if($rows > 0) {
$cols = 4; // column count
$counter = 1; //start or end row
$nbsp = $cols - ($rows % $cols); // blank column
$container_class = 'container-fluid'; // Grid class
$row_class = 'row'; // Row class
$col_class = 'col-sm-4'; // Column class
echo '<div class="'.$container_class.'">'; // Grid open
while ($item = $result->fetch_array()) {
if(($counter % $cols) == 1) { // Check new row
echo '<div class="'.$row_class.'">'; // Start new row
}
$img = "".$item['Cover'];
echo '<div class="'.$col_class.'"><img src="'.$img.'" width="180px" height="180px" alt="'.$item['Title'].'"/><h5>'.$item['Title'].'</h5></div>'; // Column content
if(($counter % $cols) == 0) { // last column then 0
echo '</div>'; // Close row
}
$counter++; // Increase counter
}
$result->free();
if($nbsp > 0) { // unused column in last row
for ($i = 0; $i < $nbsp; $i++) {
echo '<div class="'.$col_class.'"> </div>';
}
echo '</div>'; // Close row
}
echo '</div>'; // Close container
}
?>
|
But it only appears to work showing the data in one continuos column, any idea why or pointers as to where I messed up the code please?
I was pretty sure I had this from the outset but apparently not
