Jump to content

Looping a table with varied colspan in different cells


simplest
 Share

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.

 

table.gif

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...

<html>
    <style>
table {
  border-collapse: collapse;
  width: 900px;
}
th, td {
  border: 1px solid black;
}
</style>
    <?php
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>";
?>
</html>

 

Edited by simplest
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...