Why do you need it to show 8 every time? Are you trying to make sure the pages all look the same or do you have some other purpose for requiring 8 cells each time?
You can use array_pad to make sure your $rows and $columns array are always the same length or you could also hardcode the numbers into for loops
for($row_count=0;$row_count<4;$row_count++){
//do table stuff
if (!isset($row[$row_count])) {
// print an empty row
}
}Then do the same thing with your columns.
But unless you have a purpose for needing those extra cells, I'd go with Arlen's css approach. It would make life a LOT easier in this case.
<?php
<!-- Create an image gallery wrapper -->
<div class="img_gallery">
foreach ($rows as $row_number => $columns):
$row_class = 'row row-' . ($row_number + 1);
if ($row_number == 0) {
$row_class .= 'row row-first';
}
elseif (count($rows) == ($row_number + 1)) {
$row_class .= 'row row-last';
}
?>
< div class ="<? php print $row_class; ?>">
<?php foreach ($columns as $column_number => $item): ?>
< div class ="<?php print 'column column-'. ($column_number + 1); ?>">
<?php print $item; ?>
</div >
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</div>Then in a css file you'd just set your row to whatever width you'd want
div.img_gallery{
width:800px;
}
div.column{
width:200px; // or whatever the img_gallery is divided by 4
float:left;
padding:10px;
}This is a lot more better than tables.
so i realized, only now, that this is exactly the same problem i had when i was working on the links.
also, like i said before, i'm a newb, so by the time i got to the links, i figured out defining the cells' size in the css.
so, in all reality, i can take the code you spit out for the links, and change it to fit THIS problem. though i am interested in playing around with the solution you mentioned above.
i'm using drupal views to create a grid view of photos (a gallery).
the max number of columns is 4, the max rows is 2. so essentially, i have 8 photos total, 4 on each row. i've got it styled to fit the confined space in the div layer.
but, for example, when there are less than 4 photos, the php only generates 1 row, with that number of columns. i'm thinking if i can set up a "if the number of rows is less than 2, still set up that second row" and "if the number of columns is less than 4, still set up those extra columns" argument, it will display as if place-holder images are there, right?
here is the drupal code:
foreach ($rows as $row_number => $columns): ?>
php
$row_class = 'row-' . ($row_number + 1);
if ($row_number == 0) {
$row_class .= ' row-first';
}
elseif (count($rows) == ($row_number + 1)) {
$row_class .= ' row-last';
}
< tr class >="php print $row_class; ?>">
php foreach ($columns as $column_number => $item): ?>
< td class >="php print 'col-'. ($column_number + 1); ?>">
php print $item; ?>
< /td >
php endforeach; ?>
< /tr >
php endforeach; ?>
can anyone help me out on this?