toxicfelix toxicfelix - 5 months ago 16
HTML Question

How to sort data recieved in php into 3 different div tags in html?

Im using php to collect my instagram feed however all the images php collects using the instagram api are all placed in the same location(or same div) so i recieve my images

<?php foreach ($result->data as $post): ?>
<div class="images">
<!-- Renders images. @Options (thumbnail,low_resoulution,high_resolution)-->
<a class="group" rel="group1" href="<?= $post->images->standard_resolution->url ?>"><img src="<?= $post->images->thumbnail->url ?>"></a>
<?php endforeach ?> </div>


so all the images collected are turned into links and are all placed in the div images so what i would like to do is equally distribute all 20 images received into these 3 different divs using php or js.

<div class="col-md-4"></div>,
<div class="col-md-4"></div>,
<div class="col-md-4"></div>


This is my first post, code might be awkward. Thanks for the help.

Answer

You will need to split your array and then iterate it within your desired div tag.

Example:

<?php
$chunked = array_chunk($array, 3);

foreach ($chunked as $value) {
    foreach($value as $v) {
        echo '<div class="col-md-4">';
        print_r($v);
        echo '</div>';
    }
}
Comments