2015-10-22 138 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