2012-10-17 3 views
0

행과 열에 따라 결과를 배열에 표시하려고합니다. 아래 코드를 시도했지만 2 행의 결과가 같은 행이지만 다른 열이되도록 표시합니다.테이블에 조건이있는 배열로 결과 표시

여기에 지금은 5.

귀하의 제안과 도움이 많이 감사 생성이 같은 행에 있어야 row = 1 경우 내 코드

<table id="TimeTable"> 
     <thead> 
     <th style="width:20px; padding-right:10px;">No.</th> 
     <th style="width:160px; padding-right:10px;">Monday</th> 
     <th style="width:160px; padding-right:10px;">Tuesday</th> 
     <th style="width:160px; padding-right:10px;">Wednesday</th> 
     <th style="width:160px; padding-right:10px;">Thursday</th> 
     <th style="width:160px; padding-right:10px;">Friday</th> 
     </thead> 
     <tbody> 
     <?php foreach ($rows as $row): 

       for($r=1; $r<=8; $r++) { 

        if ($row->row == $r) { 
     ?> 
      <tr> 

      <td style="text-align: center; padding-right: 10px; padding-right: 10px;"><strong><?php echo $r; ?>.</strong></td> 

      <?php for($c=1; $c<=5; $c++) { ?> 

       <td><?php 

        if(($row->col == $c)) { 
         echo $row->subject." <br />Classroom: ".$row->classroom." <br />Time: ".$row->time; 
        } 

       ?></td> 

        <?php } //col for loop ?> 


      </tr> 

     <?php  } //if 
       } // row for loop 
     endforeach; ?> 
     </tbody> 
    </table> 

Here is the table what i am getting

입니다. 여기 그것을 해결하기 위해 내가 할 수있는 문제에 대한 죄송합니다

+0

내가'$의 rows'의 가치를 볼 수있는 보정입니까? – sephoy08

+0

안녕하세요, foreach 루프의 위치를 ​​td 내부로 변경하고 작동했습니다. 고맙습니다 – Saleem

답변

0

<table id="TimeTable"> 
     <thead> 
     <th style="width:20px; padding-right:10px;">No.</th> 
     <th style="width:160px; padding-right:10px;">Monday</th> 
     <th style="width:160px; padding-right:10px;">Tuesday</th> 
     <th style="width:160px; padding-right:10px;">Wednesday</th> 
     <th style="width:160px; padding-right:10px;">Thursday</th> 
     <th style="width:160px; padding-right:10px;">Friday</th> 
     </thead> 
     <tbody> 
     <?php for($r=1; $r<=8; $r++) { ?> 
      <tr> 

      <td style="text-align: center; padding-right: 10px; padding-right: 10px;"><strong><?php echo $r; ?>.</strong></td> 

      <?php for($c=1; $c<=5; $c++) { ?> 

       <td><?php 
        foreach ($rows as $row): 
         if(($row->row == $r) && ($row->col == $c)) { 
          echo $row->subject." <br />Classroom: ".$row->classroom." <br />Time: ".$row->time; 
         } 
        endforeach; 
       ?></td> 

        <?php } //col for loop ?> 

      </tr> 

     <?php  
       } // row for loop 
      ?> 
     </tbody> 
    </table> 
관련 문제