Skip to content

Instantly share code, notes, and snippets.

@cp6
Last active July 12, 2020 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cp6/e3edb35794521a8d2f08cad4f3b1e450 to your computer and use it in GitHub Desktop.
Save cp6/e3edb35794521a8d2f08cad4f3b1e450 to your computer and use it in GitHub Desktop.
PHP MySQL loop with Bootstrap 4 columns
<style>
body {
background: #0d161f;
}
.row {
background: #00b9eb;
padding: .4rem;
margin-top: .6rem;
text-align: center;
}
.a-col {
background: #de7c8d;
border: 3px solid transparent;
background-clip:padding-box;
}
</style>
<?php
$width_xsml = 12;//Columns size for extra small screen
$width_sml = 6;
$width_med = 4;
$width_large = 3;//Column size for large screen
$col_width = 12 / $width_large;//12 column layout
$row_count = 0;//The loop counter
$select = $db->prepare("SELECT `item_name` FROM `products` WHERE `is_aval` = 1;");
$select->execute();
while ($row = $select->fetch(PDO::FETCH_ASSOC)) {
if ($count % $width_large == 0) {
echo '<div class="row">';
}
$count++;
echo "<div class='col-$width_xsml col-sm-$width_sml col-md-$width_med col-lg-$width_large'>";
echo $row['item_name'];
echo '</div>';
if ($count % $width_large == 0) {
echo '</div>';
}
}
@cp6
Copy link
Author

cp6 commented Jun 6, 2019

Examples

lg:
Bootstrap columns 4

sm:
Bootstrap columns 6

xs:
Bootstrap columns 12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment