Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67469

i have 6 products and i want to show 3 products on per row using php foreach

$
0
0

I am developing an e-commerce website using php. There I want to display 3 products per row (I have 6 of them) using php foreach. Here is my code:

<div class="section">
    <div class="container">
        <?php
        $numOfCols = 4;
        $rowCount = 0;
        $bootstrapColWidth = 12 / $numOfCols;
        ?>
        <div class="row">
            <?php foreach ($results as $product) { ?>
            <div class="col-md-<?php echo $bootstrapColWidth;?>">
                <div class="well" style="width: 250px;height: auto;">
                    <div><?php echo'<img src="' . base_url().'uploads/' . $product- 
>product_image . '">'; ?></div>
                <?php echo $product->name;?> 
            </div>
        </div>
        <?php
        $rowCount++;
        if($rowCount % $numOfCols == 0) {echo '</div><div 
        class="row">'.'<br>'.'<br>';
        }
        ?>
        <?php };?>
    </div>
</div>

This code makes it show all products in a single column. I don't know how to make it show this in 2 columns instead.


Viewing all articles
Browse latest Browse all 67469

Trending Articles