Output advice

Hello,

I’m retriving 9 results from database, and I can’t find solution for my problem, I want to output them like on image

and so on…


same structure for 7, 8, 9.

How should I do that?

You could use some kind of counter to decide what style of div you’re going to use

$large = 0;
while ($row = $result->fetch()) { 
  if ($large == 0 ) { 
    // display in large div
    }
  else {
    // display in small div
    }
  $large++;
  if ($large > 2) $large =0;
 }

Or you could just keep incrementing $large and check for it being divisible by 3 to decide to use the full-width div. Or you could name the div classes to include a counter 0-2, and then just use the value of $large to form part of the div name.

1 Like

An if statement and a mod operator %

if ( $image_count % 2 ) {
  /* Output wide picture */
} else {
 /* Output the two pictures */
}

psuedo code and my logic might be a little off :grinning:
I was right my logic was off… $image_count % 2 (not 3), plus it wouldn’t really be image_count it would be more like format count.

1 Like

It could probably be done with css, using nth-child()

1 Like

Thank you guys! Have a nice day!

Example:-

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.