Forum Moderators: open

Message Too Old, No Replies

Tabular data

one row colspan3 next colspan2, possible?

         

henry0

2:51 pm on Feb 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am building a CP for the admin section of a php application .
I do not remember if I ever did it or even if is possible
how will you code (HTML, NO CSS)
below a colspan='3' row a new row that needs to be colspan='2'
there is nothing such as <td colspan=1.5> :)
50% won't work due to above inheritance
I do not want to have an empty cell
I do not want to </table> and nest a new table
Any idea?
Maybe it's a doomed question but I take my chance :)

mattur

4:16 pm on Feb 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The number of colspans/td's have to add up to the same number in each row. So if you want a 3 column table, with a row of 3, a row of 1 then a row of 2 columns:

<tr>
<td colspan="2">
<td colspan="2">
<td colspan="2">
<tr>

<tr>
<td colspan="6">
<tr>

<tr>
<td colspan="3">
<td colspan="3">
<tr>

rocknbil

4:23 pm on Feb 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, there are three options. If row 1 has a colspan of 3 and row 2 just has two rows, it will still display a "regular table" correctly even though it's not spanning three columns:

<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>&nbsp;</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]

henry0

4:27 pm on Feb 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, I knew that, it does not answer my question
or I should understand that you mean "not doable", as I forecasted it wont'be.
So I am forced to nest a table, no other alternative?

mattur

4:46 pm on Feb 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you clarify what you're trying to achieve? eg a table with...

henry0

6:24 pm on Feb 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks all,
Interesting colspan=0 concept

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
ccccc

ddddd
eeeeee

fffff
gggggg
ccccc

of 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