2016-08-24 121 views
0

我有以下做循環時,它不斷重複每個記錄的表如何解決它?全表重複每個記錄。 還爲每一行取我可以添加php while循環表重複修復

<table width="1510" border="1" align="center" cellpadding="2" cellspacing="2" class="table table-bordered" > 
     <tbody> 
     <form name="f1"> 
     <? $counter = 1; 
    $total_marks = 0; 
    $total_obtain = 0; 
    while($row_rsDept = mysql_fetch_array($rsDept)) 
     { 
     if($counter === 1) 

     { 
    ?> 
     <tr> 
      <th width="71" rowspan="3" align="center" valign="middle" scope="col"><h4>Sr. No</h4></th> 
      <th width="229" align="right" valign="top" scope="col">&nbsp;</th> 
      <th colspan="8" align="center" valign="middle" scope="col"><h3>Detail of Marks</h3></th> 
     </tr> 

     <tr> 
      <th rowspan="2" align="left" scope="row"><h4>Subject</h4></th> 
      <td colspan="2" align="center"><h4>Thoery</h4></td> 
      <td colspan="2" align="center"><h4>Practical</h4></td> 
      <td width="134" rowspan="2" align="center" valign="middle"><h4>Marks Obtain</h4></td> 
      <td width="144" rowspan="2" align="center" valign="middle"><h4>Max Marks</h4></td> 
      <td width="137" rowspan="2" align="center" valign="middle"><h4>Remarks</h4></td> 
      <td width="137" rowspan="2" align="center" valign="middle"><h4>Grace Marks</h4></td> 
     </tr> 

     <tr> 
      <td width="134">Obtained Marks</td> 
      <td width="144">Total Marks</td> 
      <td width="143">Obtained Marks</td> 
      <td width="153">Total Marks</td> 
      </tr> 
      <? } ?>  
     <tr> 
      <th align="left" scope="row">&nbsp;</th> 
      <th align="left" scope="row"><?php echo $row_rsDept['SUBJECTS']; ?></th> 
      <td><?php echo $row_rsDept['THEORYOBTAINEDMARKS']; ?></td> 
      <td><?php echo $row_rsDept['THEORYTOTALMARKS']; ?></td> 
      <td><?php echo $row_rsDept['PRACTICALOBATINEDMARKS']; ?></td> 
      <td><?php echo $row_rsDept['PRACTICALTOTALMARKS']; ?></td> 
      <td align="center" valign="middle"><?php echo $row_rsDept['MARKSOBTAINED']; ?></td> 
      <td align="center" valign="middle"><?php echo $row_rsDept['MAXMARKS']; ?></td> 
      <td align="center" valign="middle"><span class="style8"><?php echo $row_rsDept['REMARKS']; ?></span></td> 
      <td align="center" valign="middle"><?php echo $row_rsDept['GRACEMARKS']; ?></td> 
     </tr> 

     <tr> 
      <th colspan="6" align="right" valign="middle" scope="row"><h4>Total</h4></th> 
      <td align="center" valign="middle"><span class="style8"><?php echo $row_rsDept['TOTALMARKS']; ?></span></td> 
      <td align="center" valign="middle">=total of above ()</td> 
      <td align="center" valign="middle">&nbsp;</td> 
      <td align="center" valign="middle">&nbsp;</td> 
     </tr> 

<?php 
     } ?> 

     <tr> 
      <th colspan="10" align="left" valign="middle" scope="row">&nbsp;</th> 
     </tr> 
     <tr> 
      <th colspan="8" align="left" valign="middle" scope="row">&nbsp;</th> 
      <th align="left" valign="middle" scope="row">&nbsp;</th> 
      <th align="left" valign="middle" scope="row">&nbsp;</th> 
     </tr> 
     <tr> 
      <th colspan="8" align="left" valign="middle" scope="row"><br></th> 
      <th align="left" valign="middle" scope="row">&nbsp;</th> 
      <th align="left" valign="middle" scope="row">&nbsp;</th> 
      </tr> 

     </form> 
    </table> 

我試圖修復,但對我沒有工作

+0

你忘了增加/減少你的'$ counter'變量 –

+5

你的問題不清楚。你想做什麼?你期望會發生什麼?發生了什麼呢? – Mike

回答

0

內循環,你需要增加計數器變量 迴路內加入這一行

$counter++;