使用php创建基于数组的html表

时间:2014-11-10 03:55:37

标签: php codeigniter

我需要在php中基于数组生成一个html表。我有两个日期选择器,用于生成开始日期(E.G:10月22日)和结束日期(E.G:10月23日)。到目前为止,我所做的就是日期生成正确,但桌子的外观是如此混乱。而不是我想要的结果。日期不是水平垂直生成的。

表格应如下所示:

enter image description here

以下是代码片段:

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

谢谢!

0 个答案:

没有答案