Foreach Loop or a While Loop

I am trying display comics in rows of four however I am trying to arrange the comics in a pagination system where there is 20 comics to a page. However before that I need to get the layout correct, at the present I am using a foreach loop which displays the content just not how I want them to be presented.

My code
[php]





<?php foreach($comics as $list): ?>


<?= ($list['image'] <> "" ? "" : "") ?>


<?= ($list['name'] <> "" ? $list['name'] : "") ?> #<?= ($list['issue'] <> "" ? $list['issue'] : "") ?>





<?php endforeach; ?>

<?php
}else {
?>

You haven’t posted any comic yet!


<?php } ?>
[/php]

Should I use a While loop or is what I have appropriate and am I doing the foreach loops in the wrong place ?

Doesn’t matter which one you use, I prefer foreach as it looks “cleaner” (imo)

What’s wrong with the current presentation?

Hi my photo is too large apparenty
in organisational sense it is like the example below

[ Comic 1 ] [Comic 2] [Comic 3] [Comic 4]
[Comic 5]
[Comic 6] [Comic7] [Comic 8]

When it should just be in rows of four under each other if that makes sense. What am I doing incorrectly ?

It seems you’re using bootstrap and the grid system throws many people a bit off as stuffing more columns inside a row than it actually supports (12) can give unexpected results. While they wrap around and stack as you would expect if they are all the same height, uneven heights make a kind of buggy mosaic grid as you’ve described.

You can read more about it here, or a number of other places as it’s a quite common problem

solutions include setting all column items to the same static height, adding clearfix after every nth column, using javascript to set column item heights based on the tallest column item, etc.

Sponsor our Newsletter | Privacy Policy | Terms of Service