[SOLVED] Looking for feedback for improving this code
Posted: Sat Jan 29, 2005 3:10 am
Hi,
This code should produce a table, but it doesn't produce anything:
The table it should produce:
This code should produce a table, but it doesn't produce anything:
Code: Select all
<?
$cols = 4;
$arrayofitems = array('a','b','c','d','e','f','g','h','i');
$arrayofitems2 = array('description of a','description of b','description of c','description of d','description of e','description of f','description of g','description of h','description of i');
$rows = ceil(sizeof($arrayofitems) / $cols);
$counter = 0;
$content = '<table border=1 cellpadding=5>';
for($i = 0; $i < $rows; $i++) {
$content .= '<tr>';
for($j = 0; $j < $cols; $j++) {
if(!empty($arrayofitemsї$counter])) {
$content .= '<td align="center"><strong>'.$arrayofitemsї$counter].'</strong></td>';
}
else {
$content .= '<td> </td>';
}
$counter++;
}
$content .= '</tr>';
$counter = $counter - $cols;
$content .= '<tr>';
for($j = 0; $j < $cols; $j++) {
if(!empty($arrayofitemsї$counter])) {
$content .= '<td>Column '.$arrayofitems2ї$counter].'</td>';
}
else {
$content .= '<td> </td>';
}
$counter++;
}
$content .= '</tr>';
}
?>Code: Select all
<table border="1" cellpadding="5">
<tr>
<td align="center">
<strong>a</strong>
</td>
<td align="center">
<strong>b</strong>
</td>
<td align="center">
<strong>c</strong>
</td>
<td align="center">
<strong>d</strong>
</td>
</tr>
<tr>
<td>
Column description of a
</td>
<td>
Column description of b
</td>
<td>
Column description of c
</td>
<td>
Column description of d
</td>
</tr>
<tr>
<td align="center">
<strong>e</strong>
</td>
<td align="center">
<strong>f</strong>
</td>
<td align="center">
<strong>g</strong>
</td>
<td align="center">
<strong>h</strong>
</td>
</tr>
<tr>
<td>
Column description of e
</td>
<td>
Column description of f
</td>
<td>
Column description of g
</td>
<td>
Column description of h
</td>
</tr>
<tr>
<td align="center">
<strong>i</strong>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Column description of i
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>