Last active
July 12, 2020 01:56
-
-
Save cp6/e3edb35794521a8d2f08cad4f3b1e450 to your computer and use it in GitHub Desktop.
PHP MySQL loop with Bootstrap 4 columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Examples
lg:
sm:
xs: