note 32094 added to control-structures.while

From: Date: Fri, 16 May 2003 05:08:44 +0000
Subject: note 32094 added to control-structures.while
Groups: php.notes 
Request: Send a blank email to php-notes+get-48097@lists.php.net to get a copy of this message
I noticed the post above about building a multi coloumn table and making use of the : operator I did mine this way ---------------------- <table> <?php // get the list of categories $list_of_cats=new links(); $list_of_cats->show_list_of_cats(); $total_cats=count($list_of_cats->list_of_cats); $a=0; $b=0; while($a<$total_cats) { if($b==0) { echo("\n<tr>"); } echo("\n<td><input type=\"checkbox\" name=\"id_".$a."\" value=\"".$list_of_cats->list_of_cats[$a]["id"]."\"> &nbsp;".$list_of_cats->list_of_cats[$a]["category"]."</td>"); if($b==1) { echo("</tr>\n"); $b=0; $last_tr=true; } else { $b++; $last_tr=false; } $a++; } // did the last one add a tr if not add a blank one? if(!$last_tr) { // nope echo("<td>&nbsp;</td></tr>"); } ?> </table> --------------------------------- This will build a 2 coloumn table and populate each (it was part of a form). If the bottom right cell is lefte empty (that is you have an odd number of items) it correctly adds a blank cell and closes the table (XHTML valid) -- http://www.php.net/manual/en/control-structures.while.php http://master.php.net/manage/user-notes.php?action=edit+32094 http://master.php.net/manage/user-notes.php?action=delete+32094 http://master.php.net/manage/user-notes.php?action=reject+32094

« previous php.notes (#48097) next »