2014-11-07 32 views
0

我正在創建一個根據生成日期生成新列的表。在codeigniter中使用foreach處理html表格

enter image description here

我能創造它,但問題是表看起來像這樣:

enter image description here

我認爲這個問題是在我的foreach,但我不能準確判斷真實問題是。

這裏是我的代碼片段:

<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

打開討論,所以我可以幫助! – 2014-11-07 02:31:54

+0

@OkiErieRinaldi嗨!感謝您的回覆。你的意思是討論什麼? – jjydummya 2014-11-07 02:44:01

+0

https://chat.stackoverflow.com/rooms/64451/temporary-oki – 2014-11-07 02:55:56

回答

1

瞭解的代碼塊:

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

您已經生成<TR><TH>元素中。它會導致列被嵌套。

+0

是的。謝謝。 元素中的代碼用於複製列。問題是表是垂直的,我需要它水平嵌套。 – jjydummya 2014-11-10 01:00:37