RE: [PHP] cell iterations in loop

From: Date: Thu, 26 Apr 2001 20:18:06 +0000
Subject: RE: [PHP] cell iterations in loop
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-50493@lists.php.net to get a copy of this message
I'm a little unclear as to what you're trying to do, but here's my interpretation: problem 2: if it ends on a complete row... solution: put the echoing of the first and last tr's inside your conditional. When $x is initialized to 0, the if will return true, and you will output the very first tr...same at the end...so i'd have something like this: <table width="450" border="1" align="center"> <!-- we delete this first <tr> //--> <? $x = 0; #different here for later reason $length = 42; while ($x <= $length) { $x++; if ($x % 5 == 0) { echo "<tr>\n"; } echo "<td>".$x."</td>\n"; if ($x % 5 == 0) { echo "</tr>\n"; } } #also added in if($length % 5 != 0){ { #then we know that it did not end completely, so echo you're final </tr> echo "</TR>\n"; } #no need for an else block because it would do nothing ?> <!-- as well as this one </tr> //--> </table> Now if it ends on a complete row, you're fine! problem 1: what about if it ends at 42 or something, with just a closing </td>? solution: make a final check to see if you need that closing </tr> That is the if statement after you're loop... I hope this helps. -jack -----Original Message----- From: Jerry Lake [mailto:jerryl@europa.com] Sent: Thursday, April 26, 2001 2:32 PM To: php-general@lists.php.net Subject: [PHP] cell iterations in loop I've got some code that I am creating that creates a table with a loop. and it works fine for what it is, but my question is how do I compensate for rows that aren't divisible by 5 ? i.e. the empty cells at the table. additionally if it ends on a complete row (divisible by 5) I end up with an additional empty row at the end of the table, I can see why it does, I'm just trying to get around it. no big hurry on this, I'm just trying to learn more. <snip> <table width="450" border="1" align="center"> <tr> <? $x = 0; while ($x <= 42) { $x++; if ($x % 5 == 0) { echo "<td>".$x."</td>\n"; echo "</tr>\n<tr>\n"; } else { echo "<td>".$x."</td>\n"; } } ?> </tr> </table> </snip> Jerry Lake - jerryl@europa.com Interface Engineering Technician Europa Communications - http://www.europa.com Pacifier Online - http://www.pacifier.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#50493) next »