Re: [PHP] Outputting specific HTML for tag.

Mon, 22 Jan 2001 15:07:21 -0800

> 5 photos that need returning to one of the photo pages, and I have the
> photos in rows of three;  Obviously, there'd be an empty table cell.  And

> <?
>
> //  Connection code
>
> $table = "<table border=\"0\" /* Yadda Yadda */ >";
>

$table .= "<tr>";
$photocount = 0;

> while($row = mysql_fetch_array($result)) {
>
>     $row = $photo['photo'];
>
#> $table .= "<tr><td>$photo</td>"
#> $table .= "<td>$photo</td></tr>";

$table .= "<td>$photo</td>";
$photocount++;

if (($photocount % 3) == 2){
    #time to start a new row:
    $table .= "</tr><tr>";
}

>
>     }

$table .= "</tr>";

> $table .= "</table>";
>
> //  End Crap programming.
>
> ?>

The % operator is the "modulo" operator, aka "clock arithmetic".

Using $x % 3 makes it "count by threesies" and "wrap-around" to 0 when you
pass 2...

Anyway, when you hit '2', it will dump out the end row and new row tags.

BTW:  Any particular reason for building up the $table variable instead of
just spewing it out to the browser with echo (or print)?...  Unless you are
building some kind of template system, you are just making life hard on
yourself with it...

Don't miss the Zend Web Store's Grand Opening on January 23, 2001!
http://www.zend.com
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm



-- 
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]

Reply via email to