you will see I have a code in php that queries a database, where there is an ID that represents a person and another record of a debt and at the end it generates the download of a word document with its respective information, I tried to see that everything worked for 1 record and well, it does it well, the problem comes when I generalize and do it for all the records of my database, that is, for all the people that I have registered but it only downloads one file, the one of the 1st person who finds in the database and for the other people no longer does, I use the "while ($row=mysql_fetch_array($result))" to extract the information and within this while is where I do the download.
I use phpword to generate the document and do the download.
-------------------------------------------------- ---------
<?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');
}
?>
It is not possible because the http protocol is designed to download one file at a time. A possible solution is to put all the files in a zip You can do this inside the while and when you finish you send the newly generated zip http://php.net/manual/en/class.ziparchive.php