Sorry. Take that back. Just saw the original post.
The problem is that you're doing the <td> stuff AFTER deciding whether you
want to change rows or not. Imagine going through the list below when you're
on $photocount=2, which is really the third picture.
while($row = mysql_fetch_array($result)) {
$smallpic = $row['smallpic'];
if (($photocount % 3) == 2) {
echo "</tr>\n<tr>\n";
}
echo "<td>$smallpic</td>\n";
$photocount++;
}
See what happens? You end the current table row, and THEN print out the
third table cell, which really ends up on the next row.
Just move that echo statement about your if statement (leave the
auto-increment where it is), and you should be fine.
--Todd
> -----Original Message-----
> From: Todd Kerpelman
> Sent: Monday, February 26, 2001 2:10 PM
> To: [EMAIL PROTECTED]
> Subject: RE: [PHP] Table looking odd as a result of while loop?
>
>
> Hmmm... I'm pretty sure 1%3 is equal to 1.
>
> I'm suspecting you might be incrementing $photocount too
> early -- that is,
> before the if (($photocount % 3) == 2) statement. That would
> certainly
> explain the weirdness you're seeing.
>
> --Todd
>
>
> > -----Original Message-----
> > From: Johnson, Kirk [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, February 26, 2001 1:57 PM
> > To: [EMAIL PROTECTED]
> > Subject: RE: [PHP] Table looking odd as a result of while loop?
> >
> >
> > Is it because 1 % 3 is 0 with a remainder of 2? Looks like
> > the code is doing
> > just what it is written to do. The "if" evaluates to true on
> > the second
> > picture.
> >
> > Kirk
> >
> > -----Original Message-----
> > From: James, Yz [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, February 26, 2001 2:55 PM
> > To: [EMAIL PROTECTED]
> > Subject: [PHP] Table looking odd as a result of while loop?
> >
> >
> > Hi all, This is probably something dumb I'm missing, but I
> > am using the
> > following code:
> >
> > echo "<table border=\"0\">\n";
> >
> > echo "<tr>\n";
> > $photocount = 0;
> >
> > while($row = mysql_fetch_array($result)) {
> > $smallpic = $row['smallpic'];
> >
> > if (($photocount % 3) == 2) {
> > echo "</tr>\n<tr>\n";
> > }
> >
> > (There are currently 8 pics that have been uploaded). As you
> > can see that
> > the first row has returned just two columns. I'd like the
> > photos to be
> > displayed in rows of three, and if there are only 8 pictures
> > (or any othe
> > number that's not directly divisible by three) to be
> > displayed on the last
> > row. At the moment it's doing it "upside down." Any ideas?
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail:
> > [EMAIL PROTECTED]
> >
>