|
A common function on many php (or other data driven) sites is to loop
through an array and write the contents of the array to the page. It is
preferable to spread your data over multiple columns instead of writing
it all in a straight list thus forcing your readers to scroll forever.
Here is an easy way to dynamically write your cells and rows using
expressions.
-
<html><body><table><tr>
-
<?
-
$names= explode(",", "Joe,Lisa,Bill,Roger,Fred,Kenney");
-
$counter=-1;
-
-
{ $counter=$counter+1;
-
echo "<td>" . $names[$counter] . "  </td>";
-
//this is the key - if field has no remainder then field is in second column
-
$newrow=($counter % 3);
-
//echo $newrow;
-
if ($newrow == 2) echo "</tr><tr>" ;
-
} // end of while
-
//****This will write the data in three cells per row. To only do two cells
-
//** per row change the 3 in the $newrow definition to a 2 and the
-
//** comparison to a 1.
-
?>
-
<td> </td></tr></table></body></html>
|