2015-10-22 187 views
0

我試圖從php + mysql生成word。我發現代碼來生成它,我有3個查詢。我想在每個循環中更改頁面。那可能嗎?現在我用<hr>來分開它。在例子中,我只有2個大循環,但在我的頁面中,我有10個循環,並且我想要1個循環中的1個循環。這裏是我的代碼php生成word文檔更改頁面

<?php 
header("Content-type: application/vnd.ms-word"); 

header("Content-Type: application/force-download"); 
header("Content-Type: application/octet-stream"); 
header("Content-Type: application/download"); 
header("Content-Disposition: attachment; Filename=printorders.doc"); 

?> 

<?php 
include 'connection.php'; 
$result = $connection->query('SELECT * FROM main WHERE (orderid = "100000002" OR orderid = "100000003") GROUP BY orderid ORDER BY orderid'); ?> 


<?php while($row = $result->fetch_array()) { 


    $result3 = $connection->query("SELECT orderid, BillingStreet, City, Region FROM main WHERE BillingTelephone = '".$row["BillingTelephone"]."' group by orderid ORDER BY `main`.`orderdate` ASC "); 
     while($row3 = $result3->fetch_assoc()) { 
      $city = $row3["City"]; 
      $region = $row3["Region"]; 
      $address = $row3["BillingStreet"]; 
      $idorder = $row3["orderid"]; 

     } 
    ?> 
<table border="1" width="100%" cellpadding="10" cellspacing="0" align="center" id="tbl"> 
    <thead> 
     <tr> 
      <th>id</th> 
      <th>date</th> 
      <th>name</th> 
     <tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td style="text-align:center;"><?php echo $idorder;?></td> 
      <td style="text-align:center;"><?php echo $row["insert_date"];?></td> 
      <td style="text-align:center;"><?php echo $row["CustomerName"];?></td> 
     </tr> 
    </tbody> 
</table>  

<hr style="color: #f00;background-color: #f00;height: 10px;"> <!--here i want to change page--> 
<?php 
} 
?> 
+1

不,你生成HTML標記,並假裝它是一個word文檔....簡單地發送標題說文檔是word文檔不會自動將其轉換爲一個 –

+0

爲了從PHP正確生成Word文檔,您需要使用類似https://phpword.codeplex.com或https://的庫github.com/PHPOffice/PHPWord – Szandor

回答

0

如果你想使用分頁符,你可以加入這一行

<br style="page-break-before: always"> 
+0

非常感謝你的工作 – Sak