2

I am using PHP and MySQL to get data from database. My function is returning me array of objects. I am looping through them, and would like to display them in 3 columns. I have tried with CSS column-count property, but there is a problem that if number of results is even, results will be displayed in 2 columns, only if they are odd, they will be in 3 columns. I am using Bootstrap 3 also.

Here is my output code:

<div class="content">

    <div class="col-lg-12 offer">     
        <ul class="cpv">

        <?php foreach ($model as $data): ?>
            <li>
                <?= Html::img(Yii::getAlias('@web').'/img/170713.jpg', ['class' => 'img-responsive']) ?>
                <br> <?= $data->post->author?> <br>
                <a href="#"><span class="glyphicon glyphicon-chevron-up"></span></a> &nbsp;
                <a href="#"><span class="glyphicon glyphicon-chevron-down"></span> (<?= $count ?>)</a>
            </li>
        <?php endforeach ?>

        </ul>

    </div>

    <div class="clearfix"> </div>

</div>

Technologies that I am using are : PHP, MySQL, Yii2 PHP framework, HTML, CSS, Bootstrap 3.

How would you display data in 3 columns, without this problem that even number of results will be displayed in 2 columns instead of 3?

2
  • 3
    <table>, <div style="display: table-cell">, <div> with flexbox. Take your pick. Commented Feb 23, 2015 at 15:12
  • erm... what ? what is flexbox ? and where should my dynamic code go ? Commented Feb 23, 2015 at 19:24

1 Answer 1

1

You can use element with bootstrap 3 class 'col-md-4' or 'col-lg-4'

Sign up to request clarification or add additional context in comments.

1 Comment

Yes this work. I have added class="col-lg-4" to <li>. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.