你会看到我在 php 中有一个查询数据库的代码,其中有一个代表一个人的 ID 和另一个债务记录,最后它会生成一个带有相应信息的 word 文档的下载,我试图查看一切都适用于 1 条记录,而且做得很好,当我对我的数据库的所有记录进行概括并执行此操作时,问题就出现了,也就是说,对于我注册的所有人,但它只下载一个文件,第一个在数据库中找到而其他人不再找到的人之一,我使用“while ($row=mysql_fetch_array($result))”来提取信息,并在此期间进行下载。
我使用 phpword 生成文档并进行下载。
-------------------------------------------------- ---------
<?php
require_once dirname(__FILE__).'/PHPWord-master/src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
use PhpOffice\PhpWord\TemplateProcessor;
//conexion con la Bd llamada "datosgenrales" y "adeudos"
$queryID="SELECT numCuenta FROM `datosgenerales` ";
$cantidadID = mysql_query($queryID, $con);
while ($IDperson = mysql_fetch_array($cantidadID)) {
$IDperson = mysql_fetch_array($cantidadID);
$IDpersona= $IDperson['numCuenta'];
$queryCuenta = "SELECT count(*) from adeudos where cuentas='".$IDpersona."'";
$queryAdeudos = "SELECT adeudos.total as dineroTotal, adeudos.concepto as tipoAdeudo
FROM adeudos, datosgenerales
WHERE adeudos.cuentas = '".$IDpersona."'
AND datosgenerales.numCuenta ='".$IDpersona."'";
$nombre = $IDpersona; //variable para ponerla en el documento word
$resulCuenta = mysql_query($queryCuenta, $con);
$cuent=intval($cuentaRep[0]);
$templateWord = new TemplateProcessor('plantilla1.docx'); //plantilla word
// --- Asignamos valores a la plantilla
$templateWord->setValue('nombre',$nombre); //imprime en plantilla word
// --- Guardamos el documento
$templateWord->saveAs('notificacion'.$aux.'.docx');
header("Content-Disposition: attachment; filename=notificacion".$aux.".docx; charset=iso-8859-1");
echo file_get_contents('notificacion'.$aux.'.docx');
}
?>
这是不可能的,因为 http 协议旨在一次下载一个文件。一个可能的解决方案是将所有文件放在一个 zip 中您可以在其中执行此操作,完成后发送新生成的 zip http://php.net/manual/en/class.ziparchive.php