note 32094 deleted from control-structures.while by felipe
| From: | felipe@php.net | Date: | Tue, 29 Jan 2008 11:19:40 +0000 |
| Subject: | note 32094 deleted from control-structures.while by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-135511@lists.php.net to get a copy of this message | ||
Note Submitter: bob at kiwi-interactive dot com
----
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"]."\">
".$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> </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)