Reply
Loop not working... I think...
Old 12-15-2007, 06:07 AM Loop not working... I think...
SHydroxide's Avatar
Skilled Talker

Posts: 74
Name: Steve
Location: Canuckistan
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 Code:
<?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!

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

<?php
$host="localhost";
$username="usr"; 
$password="pass"; 
$database="_db"; 
$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>
__________________
This is my edited bleeding signature.

Last edited by chrishirst : 12-15-2007 at 10:47 AM.
SHydroxide is offline
Reply With Quote
View Public Profile Visit SHydroxide's homepage!
 
When You Register, These Ads Go Away!
Old 12-15-2007, 06:39 AM Re: Loop not working... I think...
Foundationflash's Avatar
Ultra Talker

Posts: 410
Name: Harry Burt
Location: Colchester, Essex, England
Your problem, I think, is with your for loop. You don't want == in the middle of it; if you want it to iterate remainder times, you want:
PHP Code:
 <?php

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

?>
__________________
Foundation Flash tutorials : www.foundation-flash.com

New Dreamed Up Web Design: www.dreamedupdesign.com
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Old 12-15-2007, 07:24 AM Re: Loop not working... I think...
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 995
Name: Jeremy Miller
Location: Reno, NV
An admin should remove the username/password in the original code above.
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 12-15-2007, 10:47 AM Re: Loop not working... I think...
chrishirst's Avatar
Super Moderator

Latest Blog Post:
Am I impressed or what?
Posts: 14,831
Location: Blackpool. UK
NP ..
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-15-2007, 12:45 PM Re: Loop not working... I think...
SHydroxide's Avatar
Skilled Talker

Posts: 74
Name: Steve
Location: Canuckistan
Ok, that's half the battle; it's generating the divs now, but not the right number.

The space for the divs is 4 wide (4 div widths wide), so what I need my little algorithm to do here is to add as many as necessary to bring the number of divs up to something divisible by five. Apparently that won't work here. Can anyone think of another way to do this, purely from a mathematical standpoint?

Thanks!
__________________
This is my edited bleeding signature.
SHydroxide is offline
Reply With Quote
View Public Profile Visit SHydroxide's homepage!
 
Old 12-15-2007, 01:57 PM Re: Loop not working... I think...
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 995
Name: Jeremy Miller
Location: Reno, NV
Well, I'm not 100% sure of what you want there, but to make it divisible by 5, change
PHP Code:
if (($numpics%4)!=0) {
  for (
$counter 0$counter < ($numpics%4); $counter += 1) { 
to

PHP Code:
if (($numpics%5)!=0) {
  for (
$counter 0$counter < ($numpics%5); $counter += 1) { 
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 12-15-2007, 02:51 PM Re: Loop not working... I think...
SHydroxide's Avatar
Skilled Talker

Posts: 74
Name: Steve
Location: Canuckistan
Quote:
Originally Posted by JeremyMiller View Post
Well, I'm not 100% sure of what you want there, but to make it divisible by 5, change
PHP Code:
if (($numpics%4)!=0) {
  for (
$counter 0$counter < ($numpics%4); $counter += 1) { 
to

PHP Code:
if (($numpics%5)!=0) {
  for (
$counter 0$counter < ($numpics%5); $counter += 1) { 

No, that's not what I need. For example, if there's 5 albums, it'll create one row of four divs, and one row of one div, right? Like so:

Code:
[a][b][c][d]
[e]
And what I need is for it to generate empty divs to fill the empty space, like so:

Code:
[a][b][c][d]
[e][ ][ ][ ]
So the result of the calculation for 5 needs to be 3.
__________________
This is my edited bleeding signature.
SHydroxide is offline
Reply With Quote
View Public Profile Visit SHydroxide's homepage!
 
Old 12-15-2007, 03:13 PM Re: Loop not working... I think...
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 995
Name: Jeremy Miller
Location: Reno, NV
Oh. I believe I've got it now.

[math]
number_of_boxes_to_add = 4 - number_of_filled_boxes%4
[/math]

For example, If you have 5, then 4-5%4 = 4-1 = 3.
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 12-16-2007, 05:40 AM Re: Loop not working... I think...
Foundationflash's Avatar
Ultra Talker

Posts: 410
Name: Harry Burt
Location: Colchester, Essex, England
PHP Code:
if (($numpics%4)!=0) {
  for (
$counter 0$counter < (- ($numpics%4)); $counter += 1) { 
__________________
Foundation Flash tutorials : www.foundation-flash.com

New Dreamed Up Web Design: www.dreamedupdesign.com

Last edited by Foundationflash : 12-16-2007 at 05:42 AM.
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Reply     « Reply to Loop not working... I think...
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15558 seconds with 12 queries