Jump to content

Looping a table with varied colspan in different cells

Recommended Posts

I can do a simple for loops to create a N x N table. However I am not sure how to approach for tables with different colspan in different cells like this?... 

Any hints or tips on how I should proceed? Thanks in advance.



Edit: This is the furthest I can come up with but there is something wrong in it and I am not sure what it is...

table {
  border-collapse: collapse;
  width: 900px;
th, td {
  border: 1px solid black;
echo "<table><tr>
        <td rowspan=\"2\">ID</td>
        <td rowspan=\"2\">Name</td>
        <td rowspan=\"2\">Date</td>";
for ($i = 1; $i <= 31; $i++) {
    echo "<td colspan=\"3\">$i</td>";
echo "</tr>";
for ($row = 1; $row <=5; $row++) {
    for ($col = 1; $col <=96; $col++) {
	    echo "<td>" . $col . "</td>";
    echo "</tr>";
echo "</tr></table>";


Edited by simplest

Share this post

Link to post
Share on other sites

I see one opening <tr> tag and 3 closing </tr> tags, so the first step is probably to figure out when you need to start a new row.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...