Hello Martin,
This turned out to be a little harder than I first thought.
But, here it is all the same, I've tried it out on my machine and got it working, but you might want to sweep through the code to make sure I got everything named back to what you are using and that no underscores creeped in where they don't belong.
I've added a new variable, called $cell, it is the <td> info for each image.
if (isset($photoscat_id)) {
$photos_query = "SELECT * FROM photos WHERE gallery = '$photoscat_id'";
$photos_result = mysql_query($photos_query) or die (mysql_error());
// Now lets get down to work...
// define the blank row
$blankrow = '<tr><td height="20" colspan="11"> </td></tr>';
// define the padding cells
$paddingcell = '<td width="20"> </td>';
// define an image cell
$cell = '<td width="100" height="130" align="center" valign="middle" bgcolor="#F3F3F3">';
// first start the table
$output = '<table border="0" cellpadding="0" cellspacing="0">'."\n";
$output .= $blankrow;
// The entry counter
$i = 0;
while ($data = mysql_fetch_array($photos_result)) {
// Is this the fifth entry to a row?
// because we start at 0, 4 is the fifth entry
if ($i == 4) {
// It is:
// Place the final entry, add an additional padding cell,
// add end the row, add blank row, reset the counter
$output .= $paddingcell;
$output .= $cell;
$output .= '<a href="' . $data['path'];
$output .= '"><img src="' . $data['thumb'];
$output .= '" border="0"></a></td>';
$output .= $paddingcell;
$output .= '</tr>'."\n";
$output .= $blankrow;
$i = 0;
} else {
// It is not:
// Check if first image of row, place image info, increment
if ($i==0) $output .= '<tr>';
$output .= $paddingcell;
$output .= $cell;
$output .= '<a href="' . $data['path'];
$output .= '"><img src="' . $data['thumb'];
$output .= '" border="0"></a></td>';
// incrementing the counter
$i += 1;
}
}
// Find out how many rows there were
// and if they were divisible by 5
$numrows = mysql_num_rows($photos_result);
if (($numrows%5) != 0) {
// we need more entry spots
while ($i < 5) {
if ($i == 4) {
// Last spot
$output .= $paddingcell;
$output .= $cell;
$output .= ' </td>';
$output .= $paddingcell;
$output .= '</tr>'."\n";
$output .= $blankrow;
$i += 1;
} else {
// another blank
$output .= $paddingcell . $cell . ' </td>';
$i += 1;
}
}
}
$output .= '</table>';
echo $output;
}
I tried to place the counting code inside of the while loop and that didn't work. Sorry, hope this helps you now.
wilson wise