简体   繁体   English

该代码重复表格标题:

[英]The code repeats the table headings :

I have a code which writes data from the database to ms document : it works pretty well but it repeats the Table headings like this : Subscriber's Name Subscriber's Account No. S-Card No. Decoder No. Contact No Date Installed Activation Date Timer 0 .. Subscriber's Name Subscriber's Account No. S-Card No. Decoder No. Contact No Date Installed Activation Date Musajhujasasa 903343434342 2013 .. Subscriber's Name Subscriber's Account No. S-Card No. Decoder No. Contact No Date Installed Activation Date 我有一个将数据从数据库写入ms文档的代码:效果很好,但它重复了表标题,如下所示:订户名称订户帐号S卡号解码器编号联系人编号安装日期激活日期计时器0。 。订户名称订户帐号S卡编号解码器编号联系人编号安装日期激活日期Musajhujasasa 903343434342 2013 ..订户名称订户帐号S卡编号解码器编号联系人编号安装日期激活日期

But I want it to display like this Subscriber's Name Subscriber's Account No. S-Card No. Decoder No. Contact No Date Installed Activation Date Timer 676737363743 Vc 67676 Dc456 07855625426 2013 . 但我希望它显示为这样的名称:订户名称订户帐号S卡编号解码器编号联系人编号安装日期激活日期计时器676737363743 Vc 67676 Dc456 07855625426 2013。 2013 Musa 7878787878 Vc3454. 2013 Musa 7878787878 Vc3454。 Dc56 089898892 2013 2013 Musajhujasasa 87u8u78u8u Vc4565 Dc786 089887387 2013 2013 Dread S77878787879 Vc 45454 Dc5653 078563536 2013 2013 Dc56 089898892 2013 2013 Musajhujasasa 87u8u78u8u Vc4565 Dc786 089887387 2013 2013惧怕S77878787879 Vc 45454 Dc5653 078563536 2013 2013

   <?php
   #this connects to my database
   include("db.inc.php"); 
   ?>
       <?php
     $query='SELECT  * 
    from clientinfo';
    $result = mysql_query($query,$con) or die (mysql_error($con));
        $fp = fopen("report.doc", 'w+'); 

    while($record = mysql_fetch_array($result)){
    $firstname = $record['firstname'];
        $refno = $record['refno'];
        $smartcard = $record['smartcard'];
        $decoderno = $record['decoderno'];
        $cell = $record['cell'];
        $date= $record['date'];
     #create word document starts here
    $str ="<table border=\"1\"><tr><td><b>Subscriber's Name</b></td><td>  <b>     Subscriber's      Account No.</b></td> <td><b>S-Card No.</b></td><td><b>Decoder     No.</b>    </td>
    <td><b>Contact No</b></td><td><b>Date Installed</b></td><td><b>Activation Date</b></td>
    </tr>
     </tr><tr><td>$firstname</td><td >$refno</td><td >$smartcard</td><td>$decoderno</td>
    <td>$cell</td><td >$date</td><td >..</td>
    </tr></table>";
       fwrite($fp, $str);  
     }
       fclose($fp);
    ?>

It repeats because the headings are inside while loop. 由于标题位于while循环内,因此会重复。

  <?php
   #this connects to my database
   include("db.inc.php"); 
   ?>
       <?php
     $query='SELECT  * 
    from clientinfo';
    $result = mysql_query($query,$con) or die (mysql_error($con));
        $fp = fopen("report.doc", 'w+'); 

$str ="<table border=\"1\"><tr><td><b>Subscriber's Name</b></td><td>  <b>     Subscriber's      Account No.</b></td> <td><b>S-Card No.</b></td><td><b>Decoder No.</b>    </td>";

while($record = mysql_fetch_array($result)){
    $firstname = $record['firstname'];
        $refno = $record['refno'];
        $smartcard = $record['smartcard'];
        $decoderno = $record['decoderno'];
        $cell = $record['cell'];
        $date= $record['date'];
     #create word document starts here
   $str.="
    <td><b>Contact No</b></td><td><b>Date Installed</b></td><td><b>Activation Date</b></td>
    </tr>
     </tr><tr><td>$firstname</td><td >$refno</td><td >$smartcard</td><td>$decoderno</td>
    <td>$cell</td><td >$date</td><td >..</td>
    </tr></table>";


fwrite($fp, $str);  
     }
       fclose($fp);
    ?>

Your doing mistake in looping, 您在循环中犯的错误,

     $str = "<table border=\"1\"><tr><td><b>Subscriber's Name</b></td><td>  <b>     Subscriber's      Account No.</b></td> <td><b>S-Card No.</b></td><td><b>Decoder     No.</b>    </td>
    <td><b>Contact No</b></td><td><b>Date Installed</b></td><td><b>Activation Date</b></td>
    </tr>
     </tr>";
   fwrite($fp, $str);  
    while($record = mysql_fetch_array($result)){
    $firstname = $record['firstname'];
        $refno = $record['refno'];
        $smartcard = $record['smartcard'];
        $decoderno = $record['decoderno'];
        $cell = $record['cell'];
        $date= $record['date'];
     #create word document starts here
    $str ="<tr><td>$firstname</td><td >$refno</td><td >$smartcard</td><td>$decoderno</td>
    <td>$cell</td><td >$date</td><td >..</td>
    </tr>";
    fwrite($fp, $str);  
     }
      $str = "</table>";
     fwrite($fp, $str);
     fclose($fp); 
     <?php
   #this connects to my database
   include("db.inc.php"); 
   ?>
       <?php
     $query='SELECT  * 
    from clientinfo';
    $result = mysql_query($query,$con) or die (mysql_error($con));
        $fp = fopen("report.doc", 'w+'); 
     if(mysql_num_rows($result))
     {    

    $str ="<table border=\"1\"><tr><td><b>Subscriber's Name</b></td><td>  <b>     Subscriber's      Account No.</b></td> <td><b>S-Card No.</b></td><td><b>Decoder     No.</b>    </td>
    <td><b>Contact No</b></td><td><b>Date Installed</b></td><td><b>Activation Date</b></td></tr>";
    while($record = mysql_fetch_array($result)){
    $firstname = $record['firstname'];
        $refno = $record['refno'];
        $smartcard = $record['smartcard'];
        $decoderno = $record['decoderno'];
        $cell = $record['cell'];
        $date= $record['date'];
     #create word document starts here

     $str .= "<tr><td>$firstname</td><td >$refno</td><td >$smartcard</td><td>$decoderno</td>
    <td>$cell</td><td >$date</td><td >..</td>
    </tr>";

     }
     $str .= "</table>";
      fwrite($fp, $str);  
     }
       fclose($fp);
    ?>

In your code you create table and table heading within while loop so it is repeating.. You have to put code of table and table heading outside of while loop. 在您的代码中,您可以在while循环内创建表和表标题,以便重复。.您必须将表和表标题的代码置于while循环之外。 Please try code given below. 请尝试下面给出的代码。

  $str = "<table border=\"1\"><tr><td><b>Subscriber's Name</b></td><td>  <b>     Subscriber's Account No.</b></td> <td><b>S-Card No.</b></td><td><b>Decoder No.</b></td>
<td><b>Contact No</b></td><td><b>Date Installed</b></td><td><b>Activation Date</b></td>
</tr>";

 while($record = mysql_fetch_array($result)){
        $firstname = $record['firstname'];
        $refno = $record['refno'];
        $smartcard = $record['smartcard'];
        $decoderno = $record['decoderno'];
        $cell = $record['cell'];
        $date= $record['date'];

        #create word document starts here
        $str .=  "<tr><td>$firstname</td><td >$refno</td><td >$smartcard</td>  
        <td>$decoderno</td><td>$cell</td><td >$date</td><td >..</td></tr>";

     }
    $str .= "</table>";
    fwrite($fp, $str);  

thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM