簡體   English   中英

該代碼重復表格標題:

[英]The code repeats the table headings :

我有一個將數據從數據庫寫入ms文檔的代碼:效果很好,但它重復了表標題,如下所示:訂戶名稱訂戶帳號S卡號解碼器編號聯系人編號安裝日期激活日期計時器0。 。訂戶名稱訂戶帳號S卡編號解碼器編號聯系人編號安裝日期激活日期Musajhujasasa 903343434342 2013 ..訂戶名稱訂戶帳號S卡編號解碼器編號聯系人編號安裝日期激活日期

但我希望它顯示為這樣的名稱:訂戶名稱訂戶帳號S卡編號解碼器編號聯系人編號安裝日期激活日期計時器676737363743 Vc 67676 Dc456 07855625426 2013。 2013 Musa 7878787878 Vc3454。 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);
    ?>

由於標題位於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);
    ?>

您在循環中犯的錯誤,

     $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);
    ?>

在您的代碼中,您可以在while循環內創建表和表標題,以便重復。.您必須將表和表標題的代碼置於while循環之外。 請嘗試下面給出的代碼。

  $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);  

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM