2017-06-17 36 views
0

我只是想表明,從表中的數據,你可以在下面這個圖片看到:
project_id是指項目在項目表名
activity_id是指活動名稱在活動表
image show table fields秀laravel V5.3表

我要顯示的結果是相同的,因爲這形象:
result i want to show at web page

這裏是我的代碼

<table id="list-Dopeople-report" class="table table-bordered responsive"> 
      <tr> 
      <th>project</th>   
      @foreach($examples as $key=>$value) 
       <th>{{activityIdToActivityNameConvert($value->activity->id)}}</th> 
      @endforeach 
      </tr>    
      @foreach($pros as $key=>$value) 
      <tr> 
       <th>{{projectIdToProjectNameConvert($value->project->id)}}</th> 
      </tr> 
      @endforeach 
    </table> 

但結果卻變得像下面的圖片:
wrong result

任何幫助將appriciated

回答

0

這裏要考慮幾件事情:

  1. 爲獲得最佳做法,請添加'thead'和'tbody'標籤
  2. 在你的第二個foreach中,你繼續使用'th',它用於表格標題。改用'td'。

主要的問題是你只能迭代'tr'-element,它會繼續添加行。您不會遍歷'td'元素,這會填滿列

<table id="list-Dopeople-report" class="table table-bordered responsive"> 
    <thead>  
     <tr> 
      <th>project</th>   
      @foreach($examples as $key=>$value) 
       <th>{{activityIdToActivityNameConvert($value->activity->id)}}</th> 
      @endforeach 
     </tr> 
    </thead> 
    <tbody> 
    <!-- here you iterate over the rows, which is ok -->   
    @foreach($pros as $key=>$value) 
     <tr> 
      <td>{{projectIdToProjectNameConvert($value->project->id)}}</td> 
      <!-- you should also iterate over the columns --> 
      @foreach($project->activities as $activity) 
       <td>{{$activity->time}}</td> 
      @endforeach 
     </tr> 
    @endforeach 
    </tbody> 
</table>