Forum Moderators: open
<table border="1">
<tr><td colspan="3">three col</td></tr>
<tr>
<td> col 1</td>
<td> col 2</td>
</tr>
</table>
This produces no errors in my offline validator, and even the W3C Validator approves, but it's still "wrong" and confusing as there's only two columns.
I know you don't want an empty cell, but when you get into large and wide tables, it's always good for things to "add up." Blank cells are a fact of life for tabular data, so when you do larger tables you need to deal with them, especially on the last row. I usually use a nested loop to create the rows, and keep track of columns:
$cols = 5;
$colcount = 0;
$out = '<table>';
foreach $v (@rows) {
for $i (0..$#rows) {
if ($colcount==0) { $out .= '<tr>'; }
$out .= "<td>data</td>";
$colcount++;
if ($colcount >= $cols) {
$out .= '</tr>';
$colcount=0;
}
}
}
So if the last row is not filled out,
if (($colcount > 0) && ($colcount < 5)) {
for $i ($colcount..$cols) { $out .= '<td> </td>'; }
$out .= '</tr>';
}
$out .= '</table>';
This way all your tables will always have the right number of cells and even out.
The last solution that I never use, but is a valid solution, is to use colspan="0". Seems odd, but if you use colspan="0" it will span whatever columns are above or below:
<table border="1">
<tr><td colspan="0">whatever number of columns</td></tr>
<tr>
<td> col 1</td>
<td> col 2</td>
</tr>
</table>
I hope one of these works for you. :-P
[edited by: rocknbil at 4:27 pm (utc) on Feb. 13, 2009]
However I inherit from many rows above and below
so I will either have a mid row cell empty <td>
or will throw in it a little something
again thanks for your help
aaaaa bbbbb cccccddddd eeeeeefffff gggggg cccccof course in my example the mid row should be a perfect align left 50 / 50
but I understand the limitations
and will deal with them