dpoxk64080 2013-06-04 01:09
浏览 5
已采纳

显示mysql结果时重复的奇怪表

There's nothing wrong with the result itself.

The image should explain itself.

The table basicly is repeating the whole table for each results instead of displaying the results with multiple lines on one table, its doing 1 line on 1 table many times.

enter image description here

Here's the code that involves it-

<?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条回答 默认 最新

  • doujia8801 2013-06-04 01:17
    关注

    There are lots of way to improve this code, but to fix your immediate problem, just take the header row out of the loop:

          <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>  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了