2013-06-04 27 views
1

Theres沒有錯誤的結果本身。顯示mysql結果時重複的奇怪表格

圖像應該解釋自己。

表格基本上是爲每個結果重複整個表格,而不是在一個表格上顯示多行結果,它多次在1個表格上執行1行。

enter image description here

下面是涉及到它 - 代碼

<?php 
$i=0; 
while ($i < $num) { 
    $f1=mysql_result($result,$i,"id"); 
    $f2=mysql_result($result,$i,"date"); 
    $f3=mysql_result($result,$i,"agentclient"); 
    $f4=mysql_result($result,$i,"propertydescription"); 
    $f5=mysql_result($result,$i,"transactiontype"); 
    $f5=mysql_result($result,$i,"applicabledocument"); 
    $f5=mysql_result($result,$i,"received"); 
    $f5=mysql_result($result,$i,"paid"); 
?> 

    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> 
    <tr valign="bottom" bgcolor="#000000"> 
     <td width="24"><span class="style1b"><strong>No.</strong></span></td> 
     <td width="105"><span class="style1b"><strong>Date</strong></span></td> 
     <td width="57"><span class="style1b"><strong>Agent/client</strong></span></td> 
     <td width="170"><span class="style1b"><strong>Property/Description</strong></span></td> 
     <td width="199"><span class="style1b"><strong>Transaction type </strong></span></td> 
     <td width="235"><span class="style1b"><strong>Applicable document </strong></span></td> 
     <td width="58"><span class="style1b"><strong>Received</strong></span></td> 
     <td width="58"><span class="style1b"><strong>Paid</strong></span></td> 
    </tr> 
    <tr valign="top" bgcolor="#FFFFFF"> 
     <td><?php echo $f1; ?></td> 
     <td><?php echo $f2; ?></td> 
     <td><?php echo $f3; ?></td> 
     <td><?php echo $f4; ?></td> 
     <td><?php echo $f5; ?></td> 
     <td><?php echo $f6; ?></td> 
     <td><?php echo $f7; ?></td> 
     <td><?php echo $f8; ?></td> 
    </tr> 
    </table> 



<?php 
    $i++; 
} 
?> 

回答

1

有很多的方法來改善這個代碼,而是要立即解決的問題,只取標題行跳出循環:

 <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> 
     <tr valign="bottom" bgcolor="#000000"> 
      <td width="24"><span class="style1b"><strong>No.</strong></span></td> 
      <td width="105"><span class="style1b"><strong>Date</strong></span></td> 
      <td width="57"><span class="style1b"><strong>Agent/client</strong></span></td> 
      <td width="170"><span class="style1b"><strong>Property/Description</strong></span></td> 
      <td width="199"><span class="style1b"><strong>Transaction type </strong></span></td> 
      <td width="235"><span class="style1b"><strong>Applicable document </strong></span></td> 
      <td width="58"><span class="style1b"><strong>Received</strong></span></td> 
      <td width="58"><span class="style1b"><strong>Paid</strong></span></td> 
     </tr> 
<?php 
$i=0; 
while ($i < $num) { 

$f1=mysql_result($result,$i,"id"); 
$f2=mysql_result($result,$i,"date"); 
$f3=mysql_result($result,$i,"agentclient"); 
$f4=mysql_result($result,$i,"propertydescription"); 
$f5=mysql_result($result,$i,"transactiontype"); 
$f5=mysql_result($result,$i,"applicabledocument"); 
$f5=mysql_result($result,$i,"received"); 
$f5=mysql_result($result,$i,"paid"); 

?> 
       <tr valign="top" bgcolor="#FFFFFF"> 
        <td><?php echo $f1; ?></td> 
        <td><?php echo $f2; ?></td> 
        <td><?php echo $f3; ?></td> 
        <td><?php echo $f4; ?></td> 
        <td><?php echo $f5; ?></td> 
        <td><?php echo $f6; ?></td> 
        <td><?php echo $f7; ?></td> 
        <td><?php echo $f8; ?></td> 
       </tr>  

       <?php 
$i++; 
} 
?> 
       </table>