Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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

Posts: 74
Name: Steve
Location: Canuckistan
Trades: 0
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 09:47 AM..
SHydroxide is offline
Reply With Quote
View Public Profile Visit SHydroxide's homepage!
 
 
Register now for full access!
Old 12-15-2007, 05:39 AM Re: Loop not working... I think...
Foundationflash's Avatar
Ultra Talker

Posts: 410
Name: Harry Burt
Location: Colchester, Essex, England
Trades: 0
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 :
Please login or register to view this content. Registration is FREE


New Dreamed Up Web Design:
Please login or register to view this content. Registration is FREE
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Old 12-15-2007, 06:24 AM Re: Loop not working... I think...
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
An admin should remove the username/password in the original code above.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 12-15-2007, 09:47 AM Re: Loop not working... I think...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
NP ..
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-15-2007, 11:45 AM Re: Loop not working... I think...
SHydroxide's Avatar
Skilled Talker

Posts: 74
Name: Steve
Location: Canuckistan
Trades: 0
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, 12:57 PM Re: Loop not working... I think...
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
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

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 12-15-2007, 01:51 PM Re: Loop not working... I think...
SHydroxide's Avatar
Skilled Talker

Posts: 74
Name: Steve
Location: Canuckistan
Trades: 0
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, 02:13 PM Re: Loop not working... I think...
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
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

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 12-16-2007, 04:40 AM Re: Loop not working... I think...
Foundationflash's Avatar
Ultra Talker

Posts: 410
Name: Harry Burt
Location: Colchester, Essex, England
Trades: 0
PHP Code:
if (($numpics%4)!=0) {
  for (
$counter 0$counter < (- ($numpics%4)); $counter += 1) { 
__________________
Foundation Flash tutorials :
Please login or register to view this content. Registration is FREE


New Dreamed Up Web Design:
Please login or register to view this content. Registration is FREE

Last edited by Foundationflash; 12-16-2007 at 04: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 Search this Thread
Search this Thread:

Advanced Search

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

BB 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.62270 seconds with 12 queries