I am trying to extract from a DB query a series of data and these data apart from printing them in a table, I also want to store them in an "implode" to generate a PDF format where the same data will be extracted by means of a "explode".
To verify the correct operation I have some "text" type inputs where the extraction of the query data should be seen separated and separated by a comma, however only the last record of a series of data prints.
Note: As a curious fact in the html table the query is reflected correctly, that is, all data is extracted, but for some reason in the "implod" and the "inputs" the same thing does not happen.
<table cellpadding="5" border="1" style="text-align:center">
<tr><th>Unidades</th><th>Productos</th><th>Precio unidad</th><th>Descuento</th></tr>
<?php
$re= ejecutarSQL::consultar("select * from compras where numSolicitud='".$numSolicitud."'");
$totalproductos = mysql_num_rows($re);
if($totalproductos>0)
{
while($fila=mysql_fetch_array($re))
{
$array_productos = array
(
"unidades" => array($fila['cantidad']),
"productos" => array($fila['categoria'].'/'.$fila['subCateg']),
"precio_unidad" => array($fila['total']),
"descuento" => array($fila['descuento'])
);
$x = 0;
while($x <= count($array_productos["unidades"]) - 1)
{
echo
"
<tr>
<td>".$array_productos["unidades"][$x]."</td>
<td>".$array_productos["productos"][$x]."</td>
<td>".$array_productos["precio_unidad"][$x]." MXN</td>
<td>".$array_productos["descuento"][$x]."%</td>
</tr>
";
$x++;
}
// A continuación se guardan en variables los datos de los productos, separados por comas
// que luego serán extraídos a través de la función explode a la hora de generar la factura
$unidades = implode(",", $array_productos["unidades"]);
$productos = implode(",", $array_productos["productos"]);
$precio_unidad = implode(",", $array_productos["precio_unidad"]);
$descuento = implode(",", $array_productos["descuento"]);
// A continuación se guardarán los datos de los productos a través de campos ocultos
}
}
?>
</table>
<input type="text" name="unidades" value="<?php echo $unidades; ?>" readonly="readonly">
<input type="text" name="productos" value="<?php echo $productos; ?>" readonly="readonly">
<input type="text" name="precio_unidad" value="<?php echo $precio_unidad; ?>" readonly="readonly">
<input type="text" name="descuento" value="<?php echo $descuento; ?>" >
<!-- Campo que hace la llamada al script que genera la factura -->
<input type="hidden" name="generar_factura" value="true" readonly="readonly">
</form>