0

I'm creating a table that generates new columns according to the dates being generated.

enter image description here

I able to create it but the problem is the table looks like this:

enter image description here

I think the problem is in my foreach but i can't pinpoint where the real problem is.

Here is the snippet of my code:

    <table class="table table-bordered">  
    <tr>
    <th></th>
    <th colspan="3"><?php 
    $from = strtotime($_POST['from']);
    $to = strtotime($_POST['to']);
    if($list_timelist):
    do 
    {
        $current = date("Y-m-d", $from);

        $from = strtotime("+1 day", $from);
        $exist = 0;
        $date1 = "";
        $date2 ="";

    ?>          
        <?php 
        endforeach;
        if($exist==1)
        {
            $date2 = date("Y-m-d", strtotime($list->time_stamp));
            echo "
            <tr>    
                <th></th>
                <th colspan='3' class='date'>$date1</th>
            <tr>";
            echo "
            <tr>
                <td></td>
                <td>UT</td>
                <td>LEAVE/ABSENT</td>
                <td>OT</td>";           
            echo "</tr>";               
        }
        else
        {
            $a=date("Y-m-d, D", strtotime($current));
            $b=date("Y-m-d", strtotime($current));
            echo "
            <tr>
                <th colspan='3' class='date'>".$a."</th>                
            <tr>";
            echo"
            <tr>
                <td></td>
                <td>UT</td>
                <td>LEAVE/ABSENT</td>
                <td>OT</td>             
            </tr>";                 
        }
    } while ($from <= $to); 
    else:
    endif;
    ?></th>
    <th colspan="3">Total</th>
    <th rowspan="2">Filed OT</th>
    <th rowspan="2">OT(previous cut-off)</th>
    <th rowspan="2">Total OT for payment</th>
  </tr>
  <tr>
    <td></td>
    <td>UT</td>
    <td>LEAVE/ABSENT</td>
    <td>OT</td>
    <td>UT<br>(hrs)</td>
    <td>LEAVE/ABSENT<br>(days)</td>
    <td>OT / Excess Time<br>(hrs)</td>
  </tr>
  <tr>          

</table>

Thanks for the help!

7
  • open a discussion so i can help! Commented Nov 7, 2014 at 2:31
  • @OkiErieRinaldi Hi! Thanks for your reply. What do you mean discussion? Commented Nov 7, 2014 at 2:44
  • chat.stackoverflow.com/rooms/64451/temporary-oki Commented Nov 7, 2014 at 2:55
  • have you join the room? Commented Nov 7, 2014 at 3:06
  • @OkiErieRinaldi Yes. I have joined the room. Commented Nov 7, 2014 at 5:00

1 Answer 1

1

Learn this block of code:

    <table class="table table-bordered" border='1'>  
    <tr>
    <th></th>
    <?php 
    $from = strtotime("2014-10-10");
    $to = strtotime("2014-10-12");

    //$interval = date_diff($from, $to);

    //$diff = $interval->format('%a');
    //echo $diff;
    do 
    {
        $current = date("Y-m-d", $from);

        $from = strtotime("+1 day", $from);
        $exist = 0;
        $date1 = "";
        $date2 ="";
            $a=date("Y-m-d, D", strtotime($current));
            $b=date("Y-m-d", strtotime($current));
            echo "

                <th colspan='3' class='date'>".$a."</th>                
            ";
    }
    while ($from <= $to); 
    ?>
    <th colspan="3">Total</th>
    <th rowspan="2">Filed OT</th>
    <th rowspan="2">OT(previous cut-off)</th>
    <th rowspan="2">Total OT for payment</th>
  </tr>
  <tr>
          <th></th>
  <?php
    $from = strtotime("2014-10-10");
    $to = strtotime("2014-10-12");
    do 
    {
        $current = date("Y-m-d", $from);

        $from = strtotime("+1 day", $from);
        $exist = 0;
        $date1 = "";
        $date2 ="";
            $a=date("Y-m-d, D", strtotime($current));
            $b=date("Y-m-d", strtotime($current));
            echo"


                <td>UT</td>
                <td>LEAVE/ABSENT</td>
                <td>OT</td>             
            ";
    }
    while ($from <= $to);     
        ?>
</tr>
</table>

You have generated <TR> inside <TH> element. It causes the columns be nested.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes. Thank you. The codes inside the <TH> element is there to duplicate the columns. The problem is the table is vertical and i need it to be nested horizontally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.