Re: Outputting specific HTML for <table> tag.

From: Date: Mon, 22 Jan 2001 22:42:49 +0000
Subject: Re: Outputting specific HTML for <table> tag.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-36108@lists.php.net to get a copy of this message
> 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

« previous php.general (#36108) next »