Click to See Complete Forum and Search --> : Loop not working... I think...


SHydroxide
12-15-2007, 04:01 AM
So I have a photo album online, and I'm having some trouble just with some formatting stuff. If you go to http://oxidephoto.ca/?level=album&id=17 you'll see that the number of pictures is not divisible by 4, so there's some empty space. I'd like to fill those with empty <div>'s, so I've devised the following:

<?php

if (($numpics%4)!=0) {
for ($counter = 0; $counter == ($numpics%4); $counter += 1) {
echo '<div class="collection">&nbsp;</div>';
}
}

?>

I initialize the $numpics variable before a big while loop, it's incremented in the loop, and then I use that above code to attempt to generate the empty <div>'s. The page loads, so I know the code is valid at least, but it's not working as I expect. The whole page's code is below. Any ideas? Thanks!

<div id="collections">
<?php while(plogger_has_pictures()) : ?>

<?php
$host="localhost";
$username="nikonnin";
$password="80673704";
$database="nikonnin_plogger";
$siteurl="http://www.oxidephoto.ca";
//Database Connection
$connection = mysql_connect($host, $username, $password);
$db = mysql_select_db($database);

$q = "SELECT * FROM `plogger_pictures` WHERE DATE_SUB(CURDATE(),INTERVAL 14 DAY) <= date_submitted";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());

while ($row=mysql_fetch_array($result))
{
$id=$row["id"];

}
?>

<?php plogger_load_picture();
// set variables for the album
$capt = plogger_get_picture_caption();
// find thumbnail width
$thumb_info = plogger_get_thumbnail_info();
$thumb_width = $thumb_info[0]; // The width of the image. It is integer data type.
$thumb_height = $thumb_info[1]; // The height of the image. It is an integer data type.
$numpics++;
?>

<div class="collection">

<a href="<?php echo plogger_get_picture_url(); ?>"><img id="thumb-<?php echo plogger_get_picture_id(); ?>" class="photos" src="<?php echo plogger_get_picture_thumb(); ?>" width="<?php echo $thumb_width; ?>px" height="<?php echo $thumb_height; ?>px" title="<?php echo $capt; ?>" alt="<?php echo $capt; ?>" /></a>

<div class="checkbox"><?php echo plogger_download_checkbox(plogger_get_picture_id()); ?></div>

<p style="width:<?php echo $thumb_width; ?>px;"><?php if ($id == plogger_get_picture_id()) {echo "NEW!<br />";} ?><?php echo $capt; ?></p>

</div>

<?php

if (($numpics%4)!=0) {
for ($counter = 0; $counter == ($numpics%4); $counter += 1) {
echo '<div class="collection">&nbsp;</div>';
}
}

?>
<?php endwhile; ?>

</div>

<?php else : ?>

<div id="no-pictures-msg">There are no pictures in this album.</div>

<?php endif; ?>

</div>

scragar
12-15-2007, 08:01 AM
replace:
$counter == ($numpics%4)
with:
$counter <= ($numpics%4)

it's a condition, so it needs to evaluate to true or false, not the number to count to :P

you can also replace your += bit:
$counter += 1
with the shorthand:
$counter++
but that's more a preference thing, they both have exactly the same functionality.