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.

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];
    }
}

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.

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 ?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.