0

Hi Everyone, I have a foreach array that prints out images one per line.

How can I print images out so I have 3 per line ?

here is the code I am working with.

        if (count($friendDataRawArray) > 0) {
            foreach ( $friendDataRawArray as $id => $friend) {

                //$name = $friend['name'];
                $photo = $friend['photo'];

            $html .= '<div class="fb-friend"><img src="' . $photo . '" alt="" class="fb-friend-img" /></div>';

It is driving me nuts, any help, and learning curve very much appreciated.

2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by brandonrunyon
0

I don't know what your array looks like, but you could do an foreach and then embed a while loop that cuts after three photos

foreach($array as $a) {
    while ($i<3) {
        print $a['photo'][$i];
    }
}
0

Hi, thanks for the quick responce.
How would I encorporate your code into mine.
As I am trying to get the image of a friend using the $id & $friend vars.
Thanks in advance.

0

Hi, I forgot to mention that I didnt want to stop at just three images, I would like to display all images, but just three per line ?

0

a div is display block, so it's always going to display on a new line, you could put a counter in your loop and then print a break tag after it gets to 3. The resulting format might look like :

<div>
    <img src="someimg.png" />
    <img src="blah.jpg" />
    <img src="xxx.png" />
    <br />
    <img />
    <img />
    <img />
    <br />
</div>

or whatever you like, as an img tag is inline, it would show 3 to a line, broken by a break, you could also do them by way of divs since they are block.

Edited by brandonrunyon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.